Use extension api to get initial locale.

feature/default_network_editable
Dan 7 years ago
parent a0df4b6892
commit b9309f689b
  1. 10
      app/scripts/background.js
  2. 2
      app/scripts/controllers/preferences.js
  3. 18
      app/scripts/lib/get-first-preferred-lang-code.js
  4. 2
      app/scripts/metamask-controller.js
  5. 1
      package.json

@ -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,

@ -11,7 +11,7 @@ class PreferencesController {
tokens: [],
useBlockie: false,
featureFlags: {},
currentLocale: 'ja',
currentLocale: opts.initLangCode,
}, opts.initState)
this.store = new ObservableStore(initState)
}

@ -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

@ -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

@ -141,6 +141,7 @@
"promise-filter": "^1.1.0",
"promise-to-callback": "^1.0.0",
"pump": "^3.0.0",
"pify": "^3.0.0",
"pumpify": "^1.3.4",
"qrcode-npm": "0.0.3",
"ramda": "^0.24.1",

Loading…
Cancel
Save