diff options
Use extension api to get initial locale.
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/get-first-preferred-lang-code.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js new file mode 100644 index 000000000..74dfe246c --- /dev/null +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -0,0 +1,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 |