From 5aff114001d21696e7a7670db56b53cf3f36afa5 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 3 Apr 2018 20:34:28 -0230 Subject: [PATCH 1/2] Ensure get-first-preferred-lang-code.js matches locale codes from local directory names and chrome extension api. --- app/scripts/lib/get-first-preferred-lang-code.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 28612f763..25221ff98 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -2,7 +2,7 @@ const extension = require('extensionizer') const promisify = require('pify') const allLocales = require('../../_locales/index.json') -const existingLocaleCodes = allLocales.map(locale => locale.code) +const existingLocaleCodes = allLocales.map(locale => locale.code.replace('_', '-')) async function getFirstPreferredLangCode () { const userPreferredLocaleCodes = await promisify( From 3c4b72bf2c5eab9c98531fcf7b0929a415b63f87 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 3 Apr 2018 20:52:17 -0230 Subject: [PATCH 2/2] Map existingLocaleCodes and userPreferredLocaleCodes to lower case in get-first-preferred-lang-code.js --- app/scripts/lib/get-first-preferred-lang-code.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/get-first-preferred-lang-code.js b/app/scripts/lib/get-first-preferred-lang-code.js index 25221ff98..e3635434e 100644 --- a/app/scripts/lib/get-first-preferred-lang-code.js +++ b/app/scripts/lib/get-first-preferred-lang-code.js @@ -2,14 +2,16 @@ const extension = require('extensionizer') const promisify = require('pify') const allLocales = require('../../_locales/index.json') -const existingLocaleCodes = allLocales.map(locale => locale.code.replace('_', '-')) +const existingLocaleCodes = allLocales.map(locale => locale.code.toLowerCase().replace('_', '-')) async function getFirstPreferredLangCode () { const userPreferredLocaleCodes = await promisify( extension.i18n.getAcceptLanguages, { errorFirst: false } )() - const firstPreferredLangCode = userPreferredLocaleCodes.find(code => existingLocaleCodes.includes(code)) + const firstPreferredLangCode = userPreferredLocaleCodes + .map(code => code.toLowerCase()) + .find(code => existingLocaleCodes.includes(code)) return firstPreferredLangCode || 'en' }