mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
preferred first languauge - check for Brave
This commit is contained in:
parent
275c31855d
commit
7edde61c12
@ -3,13 +3,7 @@ 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(
|
||||
const getPreferredLocales = extension.i18n ? promisify(
|
||||
extension.i18n.getAcceptLanguages,
|
||||
{ errorFirst: false }
|
||||
) : async () => []
|
||||
@ -25,10 +19,13 @@ const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().r
|
||||
*/
|
||||
async function getFirstPreferredLangCode () {
|
||||
let userPreferredLocaleCodes = await getPreferredLocales()
|
||||
|
||||
// safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages
|
||||
// https://github.com/MetaMask/metamask-extension/issues/4270
|
||||
if(!userPreferredLocaleCodes){
|
||||
userPreferredLocaleCodes = []
|
||||
}
|
||||
log.debug(`user preferredLocaleCodes: ${userPreferredLocaleCodes}`)
|
||||
|
||||
const firstPreferredLangCode = userPreferredLocaleCodes
|
||||
.map(code => code.toLowerCase())
|
||||
.find(code => existingLocaleCodes.includes(code))
|
||||
|
Loading…
Reference in New Issue
Block a user