-
-
Notifications
You must be signed in to change notification settings - Fork 860
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* - adds tests for fallbacks to be implemented (#2) * adds tests for fallbacks to be implemented (#2) * implementation for complex fallback variants (#2) * fixed test errors (#2) * fixed some documentation (#2) * fixes fallback test (#2) * refactor fallback tests (#2) * allow fallbackLocale to be false explicit (#2) * fixing test message (#2) * fixing use of wrong variable and type * Update src/index.js - according suggestion :+1 Co-Authored-By: kazuya kawaguchi <kawakazu80@gmail.com> Co-authored-by: kazuya kawaguchi <kawakazu80@gmail.com>
- Loading branch information
Showing
4 changed files
with
266 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import messages from './fixture/index' | ||
|
||
describe('kazupon#138 mmokross#2 - Fallback Locale as array for cascading fallbacks ...', () => { | ||
var types = [ | ||
{ | ||
description: '... none', | ||
fallbackLocale: false, | ||
tests: [ | ||
{ description: 'English', locale: 'en', expected: ['en'] }, | ||
{ description: 'English (Great Britain)', locale: 'en-GB', expected: ['en-GB', 'en'] }, | ||
{ description: 'German', locale: 'de', expected: ['de'] }, | ||
{ description: 'German (Switzerland)', locale: 'de-CH', expected: ['de-CH', 'de'] } | ||
] | ||
}, | ||
{ | ||
description: '... simple', | ||
fallbackLocale: 'en', | ||
tests: [ | ||
{ description: 'English', locale: 'en', expected: ['en'] }, | ||
{ description: 'English (Great Britain)', locale: 'en-GB', expected: ['en-GB', 'en'] }, | ||
{ description: 'German', locale: 'de', expected: ['de', 'en'] }, | ||
{ description: 'German (Switzerland)', locale: 'de-CH', expected: ['de-CH', 'de', 'en'] } | ||
] | ||
}, | ||
{ | ||
description: '... array', | ||
fallbackLocale: ['en', 'ja'], | ||
tests: [ | ||
{ description: 'English', locale: 'en', expected: ['en', 'ja'] }, | ||
{ description: 'English (Great Britain)', locale: 'en-GB', expected: ['en-GB', 'en', 'ja'] }, | ||
{ description: 'German', locale: 'de', expected: ['de', 'en', 'ja'] }, | ||
{ description: 'German (Switzerland)', locale: 'de-CH', expected: ['de-CH', 'de', 'en', 'ja'] }, | ||
{ description: 'Japanese', locale: 'ja', expected: ['ja', 'en'] } | ||
] | ||
}, | ||
{ | ||
description: '... complex', | ||
fallbackLocale: { | ||
'de-CH': ['fr', 'it'], | ||
'zh-Hant': ['zh-Hans'], | ||
'es-CL': ['es-AR'], | ||
'es': ['en-GB'], | ||
'pt': ['es-AR'], | ||
'default': ['en', 'da'] | ||
}, | ||
tests: [ | ||
{ description: 'German (Switzerland)', locale: 'de-CH', expected: ['de-CH', 'fr', 'it', 'en', 'da'] }, | ||
{ description: 'German (Switzerland) EXACT', locale: 'de-CH!', expected: ['de-CH', 'fr', 'it', 'en', 'da'] }, | ||
{ description: 'German', locale: 'de', expected: ['de', 'en', 'da'] }, | ||
{ description: 'Traditional Chinese', locale: 'zh-Hant', expected: ['zh-Hant', 'zh-Hans', 'zh', 'en', 'da'] }, | ||
{ description: 'Spanish (Spain)', locale: 'es-SP', expected: ['es-SP', 'es', 'en-GB', 'en', 'da'] }, | ||
{ description: 'Spanish (Spain) EXACT', locale: 'es-SP!', expected: ['es-SP', 'en', 'da'] }, | ||
{ description: 'French', locale: 'fr', expected: ['fr', 'en', 'da'] }, | ||
{ description: 'Portuguese (Brazil)', locale: 'pt-BR', expected: ['pt-BR', 'pt', 'es-AR', 'es', 'en-GB', 'en', 'da'] }, | ||
{ description: 'Spanish (Chile)', locale: 'es-CL', expected: ['es-CL', 'es-AR', 'es', 'en-GB', 'en', 'da'] } | ||
] | ||
} | ||
] | ||
types.forEach(function (type) { | ||
describe(type.description, () => { | ||
let i18n | ||
beforeEach(() => { | ||
i18n = new VueI18n({ | ||
locale: 'en', | ||
fallbackLocale: type.fallbackLocale, | ||
messages, | ||
modifiers: { | ||
custom: str => str.replace(/[aeiou]/g, 'x') | ||
} | ||
}) | ||
}) | ||
type.tests.forEach(function (test) { | ||
it(test.description + ': ' + test.locale + ' should fallback to ' + test.expected, () => { | ||
// console.log(test.locale + ': --> ' + i18n.getLocaleChain(test.locale)) | ||
assert.deepEqual(i18n.getLocaleChain(test.locale), test.expected) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |