aboutsummaryrefslogtreecommitdiffstats
path: root/app
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
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')
-rw-r--r--app/scripts/background.js10
-rw-r--r--app/scripts/controllers/preferences.js2
-rw-r--r--app/scripts/lib/get-first-preferred-lang-code.js18
-rw-r--r--app/scripts/metamask-controller.js2
4 files changed, 26 insertions, 6 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 8bd7766ad..c8fe1cd63 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -19,7 +19,7 @@ const setupRaven = require('./lib/setupRaven')
const reportFailedTxToSentry = require('./lib/reportFailedTxToSentry')
const setupMetamaskMeshMetrics = require('./lib/setupMetamaskMeshMetrics')
const EdgeEncryptor = require('./edge-encryptor')
-
+const getFirstPreferredLangCode = require('./lib/get-first-preferred-lang-code')
const STORAGE_KEY = 'metamask-config'
const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
@@ -58,7 +58,8 @@ setupMetamaskMeshMetrics()
async function initialize () {
const initState = await loadStateFromPersistence()
- await setupController(initState)
+ const initLangCode = await getFirstPreferredLangCode()
+ await setupController(initState, initLangCode)
log.debug('MetaMask initialization complete.')
}
@@ -90,11 +91,10 @@ async function loadStateFromPersistence () {
return versionedData.data
}
-function setupController (initState) {
+function setupController (initState, initLangCode) {
//
// MetaMask Controller
//
-
const controller = new MetamaskController({
// User confirmation callbacks:
showUnconfirmedMessage: triggerUi,
@@ -102,6 +102,8 @@ function setupController (initState) {
showUnapprovedTx: triggerUi,
// initial state
initState,
+ // initial locale code
+ initLangCode,
// platform specific api
platform,
encryptor: isEdge ? new EdgeEncryptor() : undefined,
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index dc7da90d0..b4819d951 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -11,7 +11,7 @@ class PreferencesController {
tokens: [],
useBlockie: false,
featureFlags: {},
- currentLocale: 'ja',
+ currentLocale: opts.initLangCode,
}, opts.initState)
this.store = new ObservableStore(initState)
}
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
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index bd092cea0..6e82f6011 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -57,7 +57,6 @@ module.exports = class MetamaskController extends EventEmitter {
this.defaultMaxListeners = 20
this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200)
-
this.opts = opts
const initState = opts.initState || {}
this.recordFirstTimeInfo(initState)
@@ -82,6 +81,7 @@ module.exports = class MetamaskController extends EventEmitter {
// preferences controller
this.preferencesController = new PreferencesController({
initState: initState.PreferencesController,
+ initLangCode: opts.initLangCode,
})
// currency controller