diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2018-06-15 01:37:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-15 01:37:21 +0800 |
commit | 299abee666d7f8347e062afff4f2fae47c7f6968 (patch) | |
tree | 6c14bb94e21996bdf688cc08011c8955322697ad /app | |
parent | d814bee578bfe931766804612ed57a545e4b21a8 (diff) | |
parent | d9ef72cb7ef78a1c2bf7ce119352425d72a10dc0 (diff) | |
download | tangerine-wallet-browser-299abee666d7f8347e062afff4f2fae47c7f6968.tar tangerine-wallet-browser-299abee666d7f8347e062afff4f2fae47c7f6968.tar.gz tangerine-wallet-browser-299abee666d7f8347e062afff4f2fae47c7f6968.tar.bz2 tangerine-wallet-browser-299abee666d7f8347e062afff4f2fae47c7f6968.tar.lz tangerine-wallet-browser-299abee666d7f8347e062afff4f2fae47c7f6968.tar.xz tangerine-wallet-browser-299abee666d7f8347e062afff4f2fae47c7f6968.tar.zst tangerine-wallet-browser-299abee666d7f8347e062afff4f2fae47c7f6968.zip |
Merge pull request #4524 from MetaMask/save-brave
Save Brave Fixes #4270
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/lib/get-first-preferred-lang-code.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 1e6a83ba6..41a886d74 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -2,8 +2,7 @@ const extension = require('extensionizer') const promisify = require('pify') const allLocales = require('../../_locales/index.json') -const isSupported = extension.i18n && extension.i18n.getAcceptLanguages -const getPreferredLocales = isSupported ? promisify( +const getPreferredLocales = extension.i18n ? promisify( extension.i18n.getAcceptLanguages, { errorFirst: false } ) : async () => [] @@ -18,7 +17,21 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r * */ async function getFirstPreferredLangCode () { - const userPreferredLocaleCodes = await getPreferredLocales() + let userPreferredLocaleCodes + + try { + userPreferredLocaleCodes = await getPreferredLocales() + } catch (e) { + // Brave currently throws when calling getAcceptLanguages, so this handles that. + userPreferredLocaleCodes = [] + } + + // safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages + // https://github.com/MetaMask/metamask-extension/issues/4270 + if (!userPreferredLocaleCodes){ + userPreferredLocaleCodes = [] + } + const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) @@ -26,3 +39,4 @@ async function getFirstPreferredLangCode () { } module.exports = getFirstPreferredLangCode + |