|
|
@ -2,6 +2,12 @@ const extension = require('extensionizer') |
|
|
|
const promisify = require('pify') |
|
|
|
const promisify = require('pify') |
|
|
|
const allLocales = require('../../_locales/index.json') |
|
|
|
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('_', '-')) |
|
|
|
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 () { |
|
|
|
async function getFirstPreferredLangCode () { |
|
|
|
const userPreferredLocaleCodes = await promisify( |
|
|
|
const userPreferredLocaleCodes = await getPreferredLocales() |
|
|
|
extension.i18n.getAcceptLanguages, |
|
|
|
|
|
|
|
{ errorFirst: false } |
|
|
|
|
|
|
|
)() |
|
|
|
|
|
|
|
const firstPreferredLangCode = userPreferredLocaleCodes |
|
|
|
const firstPreferredLangCode = userPreferredLocaleCodes |
|
|
|
.map(code => code.toLowerCase()) |
|
|
|
.map(code => code.toLowerCase()) |
|
|
|
.find(code => existingLocaleCodes.includes(code)) |
|
|
|
.find(code => existingLocaleCodes.includes(code)) |
|
|
|