blob: 74dfe246c386988bb6bdbc4eaae215de7ca25e5b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
|