1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-01-07 14:50:52 +00:00

auto detect browser locale if lang not stored in localstorage

This commit is contained in:
slowbackspace 2019-02-18 12:49:27 +01:00
parent f7bde2d306
commit 1eb9f71fdc
2 changed files with 15 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import { httpRequest } from 'utils/networkUtils';
import * as buildUtils from 'utils/build';
import * as storageUtils from 'utils/storage';
import * as WalletActions from 'actions/WalletActions';
import * as l10nUtils from 'utils/l10n';
import { getAccountTokens } from 'reducers/utils';
import type { Account } from 'reducers/AccountsReducer';
@ -240,7 +241,9 @@ const loadStorageData = (): ThunkAction => (dispatch: Dispatch): void => {
const language: ?string = storageUtils.get(TYPE, KEY_LANGUAGE);
if (language) {
dispatch(WalletActions.fetchLocale(language));
dispatch(WalletActions.fetchLocale(JSON.parse(language)));
} else {
dispatch(WalletActions.fetchLocale(l10nUtils.getInitialLocale()));
}
};

11
src/utils/l10n.js Normal file
View File

@ -0,0 +1,11 @@
import { LANGUAGE } from 'config/variables';
export const getInitialLocale = (defaultLocale = 'en') => {
const browserLocale = navigator.language.split('-')[0];
if (LANGUAGE.some(e => e.code === browserLocale)) {
// Array of supported languages contains the locale we're looking for
return browserLocale;
}
// if browser lang is not supported return en as default locale
return defaultLocale;
};