diff options
author | S.C. Chen <me578022@gmail.com> | 2019-02-09 03:36:37 +0800 |
---|---|---|
committer | Whymarrh Whitby <whymarrh.whitby@gmail.com> | 2019-02-09 03:36:37 +0800 |
commit | 1a4203a8c608c1ee9e13d4196f1ee0c6cac6886e (patch) | |
tree | 6edbf27e77ce1f8c16f7b00d14bdc2aa93caeba0 /app/scripts | |
parent | 57d458233b189e6752acacbaed97e8fce092b95e (diff) | |
download | tangerine-wallet-browser-1a4203a8c608c1ee9e13d4196f1ee0c6cac6886e.tar tangerine-wallet-browser-1a4203a8c608c1ee9e13d4196f1ee0c6cac6886e.tar.gz tangerine-wallet-browser-1a4203a8c608c1ee9e13d4196f1ee0c6cac6886e.tar.bz2 tangerine-wallet-browser-1a4203a8c608c1ee9e13d4196f1ee0c6cac6886e.tar.lz tangerine-wallet-browser-1a4203a8c608c1ee9e13d4196f1ee0c6cac6886e.tar.xz tangerine-wallet-browser-1a4203a8c608c1ee9e13d4196f1ee0c6cac6886e.tar.zst tangerine-wallet-browser-1a4203a8c608c1ee9e13d4196f1ee0c6cac6886e.zip |
Fix locale codes contains underscore will never be preferred (#6116)
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/lib/get-first-preferred-lang-code.js | 15 |
1 files changed, 11 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 170d508c1..469235357 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -7,7 +7,13 @@ const getPreferredLocales = extension.i18n ? promisify( { errorFirst: false } ) : async () => [] -const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().replace('_', '-')) +// mapping some browsers return hyphen instead underscore in locale codes (e.g. zh_TW -> zh-tw) +const existingLocaleCodes = {} +allLocales.forEach(locale => { + if (locale && locale.code) { + existingLocaleCodes[locale.code.toLowerCase().replace('_', '-')] = locale.code + } +}) /** * Returns a preferred language code, based on settings within the user's browser. If we have no translations for the @@ -33,9 +39,10 @@ async function getFirstPreferredLangCode () { } const firstPreferredLangCode = userPreferredLocaleCodes - .map(code => code.toLowerCase()) - .find(code => existingLocaleCodes.includes(code)) - return firstPreferredLangCode || 'en' + .map(code => code.toLowerCase().replace('_', '-')) + .find(code => existingLocaleCodes.hasOwnProperty(code)) + + return existingLocaleCodes[firstPreferredLangCode] || 'en' } module.exports = getFirstPreferredLangCode |