aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-03-22 23:09:16 +0800
committerDan <danjm.com@gmail.com>2018-03-22 23:19:19 +0800
commitb9309f689be7f55fde0a32a6e576784aa9fc1061 (patch)
tree3134db0ce2dea51930408d47a7046479422d3fb0 /app/scripts/lib
parenta0df4b6892f3a8f15d2915a062ebe1d9cdeabaec (diff)
downloadtangerine-wallet-browser-b9309f689be7f55fde0a32a6e576784aa9fc1061.tar
tangerine-wallet-browser-b9309f689be7f55fde0a32a6e576784aa9fc1061.tar.gz
tangerine-wallet-browser-b9309f689be7f55fde0a32a6e576784aa9fc1061.tar.bz2
tangerine-wallet-browser-b9309f689be7f55fde0a32a6e576784aa9fc1061.tar.lz
tangerine-wallet-browser-b9309f689be7f55fde0a32a6e576784aa9fc1061.tar.xz
tangerine-wallet-browser-b9309f689be7f55fde0a32a6e576784aa9fc1061.tar.zst
tangerine-wallet-browser-b9309f689be7f55fde0a32a6e576784aa9fc1061.zip
Use extension api to get initial locale.
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/get-first-preferred-lang-code.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js
new file mode 100644
index 000000000..74dfe246c
--- /dev/null
+++ b/app/scripts/lib/get-first-preferred-lang-code.js
@@ -0,0 +1,18 @@
+const fs = require('fs')
+const path = require('path')
+const extension = require('extensionizer')
+const promisify = require('pify')
+
+const existingLocaleCodes = fs.readdirSync(path.join(__dirname, '..', '..', '_locales'))
+
+async function getFirstPreferredLangCode () {
+ const userPreferredLocaleCodes = await promisify(
+ extension.i18n.getAcceptLanguages,
+ { errorFirst: false }
+ )().catch(err => console.log('err123', err))
+ const firstPreferredLangCode = userPreferredLocaleCodes.find(code => existingLocaleCodes.includes(code))
+ // const firstPreferredLangCode = userPreferredLocaleCodes[0]
+ return firstPreferredLangCode || 'en'
+}
+
+module.exports = getFirstPreferredLangCode