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:
commit
22c539ed43
@ -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);
|
||||
|
17
src/utils/__tests__/l10n.js
Normal file
17
src/utils/__tests__/l10n.js
Normal 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');
|
||||
});
|
||||
});
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user