diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-05-29 12:50:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-29 12:50:23 +0800 |
commit | e3ecc94a521b040d8937bd7aaed2ecc7f029c586 (patch) | |
tree | 8587c2de4e8b6456acd7ddd31b682d2432feaa2b /app/scripts | |
parent | 12492aae60b96bc439d8a7e0272b1a41924cbf1e (diff) | |
download | tangerine-wallet-browser-e3ecc94a521b040d8937bd7aaed2ecc7f029c586.tar tangerine-wallet-browser-e3ecc94a521b040d8937bd7aaed2ecc7f029c586.tar.gz tangerine-wallet-browser-e3ecc94a521b040d8937bd7aaed2ecc7f029c586.tar.bz2 tangerine-wallet-browser-e3ecc94a521b040d8937bd7aaed2ecc7f029c586.tar.lz tangerine-wallet-browser-e3ecc94a521b040d8937bd7aaed2ecc7f029c586.tar.xz tangerine-wallet-browser-e3ecc94a521b040d8937bd7aaed2ecc7f029c586.tar.zst tangerine-wallet-browser-e3ecc94a521b040d8937bd7aaed2ecc7f029c586.zip |
i18n - getFirstPreferredLangCode - guard against missing i18n api
fix for brave
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/lib/get-first-preferred-lang-code.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 5473fccf0..1e6a83ba6 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -2,6 +2,12 @@ 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( + extension.i18n.getAcceptLanguages, + { errorFirst: false } +) : async () => [] + const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().replace('_', '-')) /** @@ -12,10 +18,7 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r * */ async function getFirstPreferredLangCode () { - const userPreferredLocaleCodes = await promisify( - extension.i18n.getAcceptLanguages, - { errorFirst: false } - )() + const userPreferredLocaleCodes = await getPreferredLocales() const firstPreferredLangCode = userPreferredLocaleCodes .map(code => code.toLowerCase()) .find(code => existingLocaleCodes.includes(code)) |