mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-29 21:13:21 +00:00
Mostly what @goto-bus-stop did in 4f51deaaf7 (diff-989af75a364b65c408abe1fc3e7ac0f4R34)
> This patch allows locale keys passed to the main Uppy instance to override default keys in plugins. It's just one idea to kick things off, I'm not attached to this particular implementation.
>
> If we do this we need to make sure that all keys have unique names and that things specific to eg. a single service are "namespaced" (`transloaditEncoding` instead of `encoding`).
>
> The benefit to this is that there is a central point of configuration for languages, so there could be language packs with strings for eg Czech at `@uppy/lang-cz` (or `@uppy/langs/cz`) that would be very easy to use.
81 lines
2.6 KiB
JavaScript
81 lines
2.6 KiB
JavaScript
const Translator = require('./Translator')
|
|
// TODO use stubs instead
|
|
const russian = require('../../../../locales/ru_RU')
|
|
const english = require('../../../../locales/en_US')
|
|
|
|
describe('Translator', () => {
|
|
describe('translate', () => {
|
|
it('should translate a string', () => {
|
|
const translator = new Translator(russian)
|
|
expect(translator.translate('chooseFile')).toEqual('Выберите файл')
|
|
})
|
|
|
|
it('should translate a string with non-string elements', () => {
|
|
const translator = new Translator({
|
|
strings: {
|
|
test: 'Hello %{who}!',
|
|
test2: 'Hello %{who}'
|
|
}
|
|
})
|
|
|
|
const who = Symbol('who')
|
|
expect(translator.translateArray('test', { who: who })).toEqual(['Hello ', who, '!'])
|
|
// No empty string at the end.
|
|
expect(translator.translateArray('test2', { who: who })).toEqual(['Hello ', who])
|
|
})
|
|
})
|
|
|
|
describe('translation strings inheritance / overriding', () => {
|
|
const launguagePackLoadedInCore = english
|
|
const defaultStrings = {
|
|
strings: {
|
|
youHaveChosen: 'You have chosen 123: %{fileName}'
|
|
}
|
|
}
|
|
const userSuppliedStrings = {
|
|
strings: {
|
|
youHaveChosen: 'Beep boop: %{fileName}'
|
|
}
|
|
}
|
|
|
|
it('should prioritize language pack strings from Core over default', () => {
|
|
const translator = new Translator([ defaultStrings, launguagePackLoadedInCore ])
|
|
expect(
|
|
translator.translate('youHaveChosen', { fileName: 'img.jpg' })
|
|
).toEqual('You have chosen: img.jpg')
|
|
})
|
|
|
|
it('should prioritize user-supplied strings over language pack from Core', () => {
|
|
const translator = new Translator([ defaultStrings, launguagePackLoadedInCore, userSuppliedStrings ])
|
|
expect(
|
|
translator.translate('youHaveChosen', { fileName: 'img.jpg' })
|
|
).toEqual('Beep boop: img.jpg')
|
|
})
|
|
})
|
|
|
|
describe('interpolation', () => {
|
|
it('should interpolate a string', () => {
|
|
const translator = new Translator(english)
|
|
expect(
|
|
translator.translate('youHaveChosen', { fileName: 'img.jpg' })
|
|
).toEqual('You have chosen: img.jpg')
|
|
})
|
|
})
|
|
|
|
describe('pluralization', () => {
|
|
it('should translate a string', () => {
|
|
const translator = new Translator(russian)
|
|
expect(
|
|
translator.translate('filesChosen', { smart_count: 18 })
|
|
).toEqual('Выбрано 18 файлов')
|
|
|
|
expect(
|
|
translator.translate('filesChosen', { smart_count: 1 })
|
|
).toEqual('Выбран 1 файл')
|
|
|
|
expect(
|
|
translator.translate('filesChosen', { smart_count: 0 })
|
|
).toEqual('Выбрано 0 файлов')
|
|
})
|
|
})
|
|
})
|