Merge pull request #4390 from MetaMask/i18n-brave-fix

i18n - getFirstPreferredLangCode - guard against missing i18n api
feature/default_network_editable
kumavis 7 years ago committed by GitHub
commit 39069710d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/scripts/lib/get-first-preferred-lang-code.js

@ -2,6 +2,12 @@ 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(
extension.i18n.getAcceptLanguages,
{ errorFirst: false }
) : async () => []
const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().replace('_', '-'))
/**
@ -12,10 +18,7 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r
*
*/
async function getFirstPreferredLangCode () {
const userPreferredLocaleCodes = await promisify(
extension.i18n.getAcceptLanguages,
{ errorFirst: false }
)()
const userPreferredLocaleCodes = await getPreferredLocales()
const firstPreferredLangCode = userPreferredLocaleCodes
.map(code => code.toLowerCase())
.find(code => existingLocaleCodes.includes(code))

Loading…
Cancel
Save