Browse Source

Locale umd build

Should work everywhere now
Artur Paikin 9 years ago
parent
commit
fe3475737b

+ 1 - 2
bin/build-umd

@@ -11,9 +11,8 @@ __base="$(basename ${__file} .sh)"
 
 SRC="src/index.js"
 OUT="uppy.js"
-
 OUTDIR="dist"
-TRANSFORMS="[ babelify ]"
+
 FLAGS="-t [ babelify ] --standalone Uppy"
 
 mkdir -p "${OUTDIR}"

+ 25 - 0
bin/build-umd-locale

@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+set -o pipefail
+set -o errexit
+set -o nounset
+# set -o xtrace
+
+# Set magic variables for current file & dir
+__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
+__base="$(basename ${__file} .sh)"
+
+SRC="src/locale/ru_RU.js"
+OUT="ru_RU.js"
+OUTDIR="dist/locale"
+
+FLAGS="-t [ babelify ]"
+
+mkdir -p "${OUTDIR}"
+
+for file in ./src/locale/*.js; do
+  # echo "$file";
+  node_modules/.bin/browserify $file $FLAGS > $OUTDIR/${file##*/};
+done
+
+node_modules/.bin/browserify $SRC $FLAGS > $OUTDIR/$OUT

+ 1 - 1
package.json

@@ -7,7 +7,7 @@
     "build:css": "bin/build-css",
     "build:lib": "babel src -d lib --stage 0",
     "build:umd:min": "./bin/build-umd",
-    "build:umd": "./bin/build-umd",
+    "build:umd": "./bin/build-umd && ./bin/build-umd-locale",
     "build": "npm run build:lib && npm run build:umd && npm run build:umd:min && npm run build:css",
     "clean": "rm -rf lib && rm -rf dist",
     "lint": "eslint src/**/*.js",

+ 2 - 4
src/core/Core.js

@@ -49,10 +49,6 @@ export default class Core {
  * @returns {string} translated string
  */
   translate(string) {
-    // const currentLocale = this.opts.locale;
-    // console.log(currentLocale);
-    // const dictionaryPath = '../locale/en_US.json';
-    // const dictionary = require('../locale/en_US.json');
     const dictionary = this.opts.locale;
 
     // if locale is unspecified, return the original string
@@ -98,6 +94,8 @@ export default class Core {
       method : 'run'
     });
 
+    console.log(`translation is all like: ${this.translate('Choose a file')}` );
+
     // First we select only plugins of current type,
     // then create an array of runType methods of this plugins
     let typeMethods = this.types.filter(type => {

+ 4 - 1
src/index.js

@@ -1,7 +1,10 @@
 import Core from './core';
 import plugins from './plugins';
 
+const locale = {};
+
 export default {
   Core,
-  plugins
+  plugins,
+  locale
 };

+ 5 - 2
src/locale/en_US.json → src/locale/en_US.js

@@ -1,4 +1,7 @@
-{
+var en_US = {
   "Choose a file": "Choose a file",
   "or drag & drop": "or drag & drop"
-}
+};
+
+Uppy.locale.en_US = en_US;
+export default en_US;

+ 5 - 2
src/locale/ru_RU.json → src/locale/ru_RU.js

@@ -1,4 +1,7 @@
-{
+var ru_RU = {
   "Choose a file": "Выберите файл",
   "or drag & drop": "или перенесите его сюда"
-}
+};
+
+Uppy.locale.ru_RU = ru_RU;
+export default ru_RU;

+ 2 - 2
website/src/examples/i18n/app.es6

@@ -1,9 +1,9 @@
 import Uppy from 'uppy/core';
 import { DragDrop, Tus10 } from 'uppy/plugins';
 
-const russianLang = require('../../../../src/locale/ru_RU.json');
+const ru_RU = require('../../../../src/locale/ru_RU.js');
 
-const uppy = new Uppy({wait: false, locale: russianLang});
+const uppy = new Uppy({wait: false, locale: ru_RU});
 const files = uppy
   .use(DragDrop, {selector: '#upload-target'})
   .use(Tus10, {endpoint: 'http://master.tus.io:8080/files/'})

+ 10 - 0
website/src/examples/i18n/app.html

@@ -1,3 +1,13 @@
+<script src="/uppy/uppy.js"></script>
+<script src="/uppy/locale/ru_RU.js"></script>
+<script>
+var uppy = new Uppy.Core({locale: Uppy.locale.ru_RU});
+uppy.use(Uppy.plugins.Tus10);
+uppy.run();
+
+console.log('Uppy ' + uppy.type + ' loaded from CDN with tus enabled');
+</script>
+
 <!-- Basic Uppy styles -->
 <link rel="stylesheet" href="/css/uppy.css">
 

+ 1 - 1
website/src/examples/i18n/index.ejs

@@ -11,7 +11,7 @@ Here you'll see a demo of how you might set Uppy to work with multiple languages
 
 <link rel="stylesheet" href="app.css">
 <% include app.html %>
-<script src="app.js"></script>
+<script src="123app.js"></script>
 
 <hr />