Sfoglia il codice sorgente

core: Pluralize collections (locales, just l like plugins)

Kevin van Zonneveld 9 anni fa
parent
commit
2e7746eea7

+ 1 - 0
CHANGELOG.md

@@ -53,6 +53,7 @@ Ideas that will be planned and find their way into a release at one point
 - [ ] website: Decide on tagline(s) (@kvz, @hedgerh, @arturi, @tim-kos)
 - [ ] website: Polish taglines (@arturi)
 - [ ] website: scrollbars on code samples (@arturi)
+- [x] core: Pluralize collections (locales, just l like plugins) (@kvz)
 - [x] core: Rename `selecter` to `getter` or `acquire` (@kvz)
 - [x] complete: `Complete` Plugin of type/stage: `presenter`. "You have successfully uploaded `3 files`". Button: Close modal. (@arturi)
 - [x] dragdrop: (error) handling when you press Upload with no files (@arturi)

+ 2 - 2
bin/build-bundle-locale → bin/build-bundle-locales

@@ -9,13 +9,13 @@ __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
 __base="$(basename ${__file} .sh)"
 
-OUTDIR="dist/locale"
+OUTDIR="dist/locales"
 
 FLAGS="-t [ babelify ]"
 
 mkdir -p "${OUTDIR}"
 
-for file in ./src/locale/*.js; do
+for file in ./src/locales/*.js; do
   # echo "$file";
   node_modules/.bin/browserify $file $FLAGS > $OUTDIR/${file##*/};
 done

+ 1 - 1
package.json

@@ -19,7 +19,7 @@
     "build:lib": "babel src -d lib --stage 0",
     "build:bundle:fullpath": "env OUT=uppy-fp.js ./bin/build-bundle --full-paths",
     "build:bundle:min": "./bin/build-bundle",
-    "build:bundle": "./bin/build-bundle && ./bin/build-bundle-locale",
+    "build:bundle": "./bin/build-bundle && ./bin/build-bundle-locales",
     "release": "npm version ${SEMANTIC:-patch} -m \"Release %s\" && git push && git push --tags && npm publish",
     "release:major": "env SEMANTIC=major npm run release",
     "release:minor": "env SEMANTIC=minor npm run release",

+ 4 - 4
src/core/Core.js

@@ -5,14 +5,14 @@ import ee from 'event-emitter'
 /**
  * Main Uppy core
  *
- * @param {object} opts general options, like locale, to show modal or not to show
+ * @param {object} opts general options, like locales, to show modal or not to show
  */
 export default class Core {
   constructor (opts) {
     // set default options
     const defaultOptions = {
-      // load English as the default locale
-      locale: require('../locale/en_US.js'),
+      // load English as the default locales
+      locales: require('../locales/en_US.js'),
       autoProceed: true,
       debug: false
     }
@@ -28,7 +28,7 @@ export default class Core {
     // Container for different types of plugins
     this.plugins = {}
 
-    this.translator = new Translator({locale: this.opts.locale})
+    this.translator = new Translator({locales: this.opts.locales})
     this.i18n = this.translator.translate.bind(this.translator)
     // console.log(this.i18n('filesChosen', {smart_count: 3}))
 

+ 3 - 3
src/core/Translator.js

@@ -60,10 +60,10 @@ export default class Translator {
  */
   translate (key, options) {
     if (options && options.smart_count) {
-      var plural = this.opts.locale.pluralize(options.smart_count)
-      return this.interpolate(this.opts.locale.strings[key][plural], options)
+      var plural = this.opts.locales.pluralize(options.smart_count)
+      return this.interpolate(this.opts.locales.strings[key][plural], options)
     }
 
-    return this.interpolate(this.opts.locale.strings[key], options)
+    return this.interpolate(this.opts.locales.strings[key], options)
   }
 }

+ 2 - 2
src/index.js

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

+ 1 - 1
src/locale/en_US.js → src/locales/en_US.js

@@ -24,7 +24,7 @@ en_US.pluralize = function (n) {
 }
 
 if (typeof window !== 'undefined' && typeof window.Uppy !== 'undefined') {
-  window.Uppy.locale.en_US = en_US
+  window.Uppy.locales.en_US = en_US
 }
 
 export default en_US

+ 1 - 1
src/locale/ru.js → src/locales/ru.js

@@ -25,7 +25,7 @@ ru.pluralize = function (n) {
 }
 
 if (typeof window !== 'undefined' && typeof window.Uppy !== 'undefined') {
-  window.Uppy.locale.ru = ru
+  window.Uppy.locales.ru = ru
 }
 
 export default ru

+ 6 - 6
test/translator.spec.js

@@ -2,8 +2,8 @@ var test = require('tape')
 var Core = require('../src/core/index.js')
 
 test('translation', function (t) {
-  const russian = require('../src/locale/ru.js')
-  const core = new Core({locale: russian})
+  const russian = require('../src/locales/ru.js')
+  const core = new Core({locales: russian})
 
   t.equal(
     core.translator.translate('chooseFile'),
@@ -15,8 +15,8 @@ test('translation', function (t) {
 })
 
 test('interpolation', function (t) {
-  const english = require('../src/locale/en_US.js')
-  const core = new Core({locale: english})
+  const english = require('../src/locales/en_US.js')
+  const core = new Core({locales: english})
 
   t.equal(
     core.translator.translate('youHaveChosen', {'fileName': 'img.jpg'}),
@@ -28,8 +28,8 @@ test('interpolation', function (t) {
 })
 
 test('pluralization', function (t) {
-  const russian = require('../src/locale/ru.js')
-  const core = new Core({locale: russian})
+  const russian = require('../src/locales/ru.js')
+  const core = new Core({locales: russian})
 
   t.equal(
     core.translator.translate('filesChosen', {'smart_count': '18'}),

+ 1 - 1
website/src/api/docs.md

@@ -14,7 +14,7 @@ Main Uppy core
 
 **Parameters**
 
--   `opts` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** general options, like locale, to show modal or not to show
+-   `opts` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** general options, like locales, to show modal or not to show
 
 ### run
 

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

@@ -2,7 +2,7 @@ import Uppy from 'uppy/core'
 import { Tus10 } from 'uppy/plugins'
 
 const ru = require('../../../../src/locale/ru.js')
-const uppy = new Uppy({wait: false, locale: ru})
+const uppy = new Uppy({wait: false, locales: ru})
 
 uppy
   .use(Tus10, {endpoint: 'http://master.tus.io:8080/files/'})

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

@@ -5,9 +5,9 @@
 
 <!-- Load Uppy pre-built bundled version and Russian language pack -->
 <script src="/uppy/uppy.js"></script>
-<script src="/uppy/locale/ru.js"></script>
+<script src="/uppy/locales/ru.js"></script>
 <script>
-  var uppy = new Uppy.Core({locale: Uppy.locale.ru});
+  var uppy = new Uppy.Core({locales: Uppy.locales.ru});
   uppy.use(Uppy.plugins.DragDrop, {target: '.UppyDragDrop-form'});
   uppy.use(Uppy.plugins.Tus10, {endpoint: 'http://master.tus.io:8080/files/'});
   uppy.run();