diff options
author | Jenny Pollack <jennypollack3@gmail.com> | 2018-06-07 09:24:45 +0800 |
---|---|---|
committer | Jenny Pollack <jennypollack3@gmail.com> | 2018-06-07 09:24:45 +0800 |
commit | 7edde61c1231b1df6023ac458559b8a008bf300d (patch) | |
tree | d1c73b4cf2daa3d6df99376766be44149245b0d6 /app/scripts/lib/get-first-preferred-lang-code.js | |
parent | 275c31855da73299f4e0838d9ecbcc4278b8431c (diff) | |
download | tangerine-wallet-browser-7edde61c1231b1df6023ac458559b8a008bf300d.tar tangerine-wallet-browser-7edde61c1231b1df6023ac458559b8a008bf300d.tar.gz tangerine-wallet-browser-7edde61c1231b1df6023ac458559b8a008bf300d.tar.bz2 tangerine-wallet-browser-7edde61c1231b1df6023ac458559b8a008bf300d.tar.lz tangerine-wallet-browser-7edde61c1231b1df6023ac458559b8a008bf300d.tar.xz tangerine-wallet-browser-7edde61c1231b1df6023ac458559b8a008bf300d.tar.zst tangerine-wallet-browser-7edde61c1231b1df6023ac458559b8a008bf300d.zip |
preferred first languauge - check for Brave
Diffstat (limited to 'app/scripts/lib/get-first-preferred-lang-code.js')
-rw-r--r-- | app/scripts/lib/get-first-preferred-lang-code.js | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 5e524f9eb..89239a013 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -3,13 +3,7 @@ const promisify = require('pify') const allLocales = require('../../_locales/index.json') const log = require('loglevel') -// as far as i can tell, this is truthy in the case of Brave browser -// where extension.i18n.getAcceptLanguages throws due to not being implemented -// Unchecked runtime.lastError while running i18n.getAcceptLanguages: Access to extension API denied. -// https://stackoverflow.com/questions/28431505/unchecked-runtime-lasterror-when-using-chrome-api -const isSupported = extension.i18n && extension.i18n.getAcceptLanguages - -const getPreferredLocales = isSupported ? promisify( +const getPreferredLocales = extension.i18n ? promisify( extension.i18n.getAcceptLanguages, { errorFirst: false } ) : async () => [] @@ -25,10 +19,13 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r */ async function getFirstPreferredLangCode () { let userPreferredLocaleCodes = await getPreferredLocales() + + // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages + // https://github.com/MetaMask/metamask-extension/issues/4270 if(!userPreferredLocaleCodes){ userPreferredLocaleCodes = [] } - log.debug(`user preferredLocaleCodes: ${userPreferredLocaleCodes}`) + const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) |