mirror of
https://github.com/trezor/trezor-wallet
synced 2025-01-09 07:30:58 +00:00
auto detect browser locale if lang not stored in localstorage
This commit is contained in:
parent
f7bde2d306
commit
1eb9f71fdc
@ -12,6 +12,7 @@ import { httpRequest } from 'utils/networkUtils';
|
|||||||
import * as buildUtils from 'utils/build';
|
import * as buildUtils from 'utils/build';
|
||||||
import * as storageUtils from 'utils/storage';
|
import * as storageUtils from 'utils/storage';
|
||||||
import * as WalletActions from 'actions/WalletActions';
|
import * as WalletActions from 'actions/WalletActions';
|
||||||
|
import * as l10nUtils from 'utils/l10n';
|
||||||
|
|
||||||
import { getAccountTokens } from 'reducers/utils';
|
import { getAccountTokens } from 'reducers/utils';
|
||||||
import type { Account } from 'reducers/AccountsReducer';
|
import type { Account } from 'reducers/AccountsReducer';
|
||||||
@ -240,7 +241,9 @@ const loadStorageData = (): ThunkAction => (dispatch: Dispatch): void => {
|
|||||||
|
|
||||||
const language: ?string = storageUtils.get(TYPE, KEY_LANGUAGE);
|
const language: ?string = storageUtils.get(TYPE, KEY_LANGUAGE);
|
||||||
if (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
11
src/utils/l10n.js
Normal 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;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user