blob: 849018f2679a4f20b40d5709585e03cebdc86039 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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 }
)()
const firstPreferredLangCode = userPreferredLocaleCodes.find(code => existingLocaleCodes.includes(code))
return firstPreferredLangCode || 'en'
}
module.exports = getFirstPreferredLangCode
|