aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/get-first-preferred-lang-code.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-06-20 08:09:52 +0800
committerDan <danjm.com@gmail.com>2018-06-20 08:09:52 +0800
commit06307ef8aeb707faa6aaad6eab9b31e8c9eac173 (patch)
tree402355ca71c5e973c4017f2d842421f04caa1db2 /app/scripts/lib/get-first-preferred-lang-code.js
parentbb855707efbcb754f5e4ee4e124f69308bca037d (diff)
parent40fad619088bd955d5505cc839a7521ac43235f9 (diff)
downloadtangerine-wallet-browser-06307ef8aeb707faa6aaad6eab9b31e8c9eac173.tar
tangerine-wallet-browser-06307ef8aeb707faa6aaad6eab9b31e8c9eac173.tar.gz
tangerine-wallet-browser-06307ef8aeb707faa6aaad6eab9b31e8c9eac173.tar.bz2
tangerine-wallet-browser-06307ef8aeb707faa6aaad6eab9b31e8c9eac173.tar.lz
tangerine-wallet-browser-06307ef8aeb707faa6aaad6eab9b31e8c9eac173.tar.xz
tangerine-wallet-browser-06307ef8aeb707faa6aaad6eab9b31e8c9eac173.tar.zst
tangerine-wallet-browser-06307ef8aeb707faa6aaad6eab9b31e8c9eac173.zip
Merge branch 'develop' into i4409-i4410-ens-input-enhancements
Diffstat (limited to 'app/scripts/lib/get-first-preferred-lang-code.js')
-rw-r--r--app/scripts/lib/get-first-preferred-lang-code.js20
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
+