1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-30 12:18:09 +00:00

Merge pull request #501 from trezor/feature/l10n-tests

Feature/l10n tests
This commit is contained in:
Vladimir Volek 2019-04-15 13:39:52 +02:00 committed by GitHub
commit 22c539ed43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions

View File

@ -287,7 +287,7 @@ const loadStorageData = (): ThunkAction => (dispatch: Dispatch): void => {
if (language) {
dispatch(WalletActions.fetchLocale(JSON.parse(language)));
} else {
dispatch(WalletActions.fetchLocale(l10nUtils.getInitialLocale()));
dispatch(WalletActions.fetchLocale(l10nUtils.getInitialLocale(navigator.language)));
}
const localCurrency: ?string = storageUtils.get(TYPE, KEY_LOCAL_CURRENCY);

View File

@ -0,0 +1,17 @@
import * as utils from '../l10n';
describe('l10n utils: getInitialLocale', () => {
it('default lang', () => {
expect(utils.getInitialLocale(0)).toBe('en');
expect(utils.getInitialLocale(null)).toBe('en');
expect(utils.getInitialLocale(undefined)).toBe('en');
expect(utils.getInitialLocale('dadada')).toBe('en');
expect(utils.getInitialLocale('')).toBe('en');
});
it('browser locales', () => {
expect(utils.getInitialLocale('zh')).toBe('zh');
expect(utils.getInitialLocale('cs-CZ')).toBe('cs');
expect(utils.getInitialLocale('en_GB')).toBe('en');
});
});

View File

@ -1,7 +1,9 @@
import { LANGUAGE } from 'config/app';
export const getInitialLocale = (defaultLocale = 'en') => {
const browserLocale = navigator.language.split('-')[0];
export const getInitialLocale = (navigatorLanguage, defaultLocale = 'en') => {
if (!navigatorLanguage) return defaultLocale;
const browserLocale = navigatorLanguage.split('-')[0];
if (LANGUAGE.some(e => e.code === browserLocale)) {
// Array of supported languages contains the locale we're looking for
return browserLocale;