aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenny Pollack <jennypollack3@gmail.com>2018-06-07 09:10:05 +0800
committerJenny Pollack <jennypollack3@gmail.com>2018-06-07 09:10:05 +0800
commit275c31855da73299f4e0838d9ecbcc4278b8431c (patch)
tree0cb5fcea64b2b520d49046d3c5f2ded8c4be4630
parent191c3df108562d3f72d6206dfdcd591ad5c80e73 (diff)
downloadtangerine-wallet-browser-275c31855da73299f4e0838d9ecbcc4278b8431c.tar
tangerine-wallet-browser-275c31855da73299f4e0838d9ecbcc4278b8431c.tar.gz
tangerine-wallet-browser-275c31855da73299f4e0838d9ecbcc4278b8431c.tar.bz2
tangerine-wallet-browser-275c31855da73299f4e0838d9ecbcc4278b8431c.tar.lz
tangerine-wallet-browser-275c31855da73299f4e0838d9ecbcc4278b8431c.tar.xz
tangerine-wallet-browser-275c31855da73299f4e0838d9ecbcc4278b8431c.tar.zst
tangerine-wallet-browser-275c31855da73299f4e0838d9ecbcc4278b8431c.zip
first language - add check for brave browser on getAcceptLanguages
-rw-r--r--app/scripts/lib/get-first-preferred-lang-code.js12
1 files changed, 11 insertions, 1 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..5e524f9eb 100644
--- a/app/scripts/lib/get-first-preferred-lang-code.js
+++ b/app/scripts/lib/get-first-preferred-lang-code.js
@@ -1,8 +1,14 @@
const extension = require('extensionizer')
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(
extension.i18n.getAcceptLanguages,
{ errorFirst: false }
@@ -18,7 +24,11 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r
*
*/
async function getFirstPreferredLangCode () {
- const userPreferredLocaleCodes = await getPreferredLocales()
+ let userPreferredLocaleCodes = await getPreferredLocales()
+ if(!userPreferredLocaleCodes){
+ userPreferredLocaleCodes = []
+ }
+ log.debug(`user preferredLocaleCodes: ${userPreferredLocaleCodes}`)
const firstPreferredLangCode = userPreferredLocaleCodes
.map(code => code.toLowerCase())
.find(code => existingLocaleCodes.includes(code))