From 52ce85637076199498d5bf21a09c8ca4c33f49cc Mon Sep 17 00:00:00 2001 From: FelisNivalis <88343630+FelisNivalis@users.noreply.github.com> Date: Tue, 27 Sep 2022 22:39:24 +0200 Subject: [PATCH] Update translations.js fixed `mapLanguageCodeToId` to correctly choose region --- src/js/translations.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/translations.js b/src/js/translations.js index 9d976a41..06db2f0d 100644 --- a/src/js/translations.js +++ b/src/js/translations.js @@ -32,7 +32,10 @@ function mapLanguageCodeToId(languageKey) { // Try to match by key or short key for (const id in LANGUAGES) { const data = LANGUAGES[id]; - const code = data.code.toLowerCase(); + const shortCode = data.code.toLowerCase(); + const region = data.region.toLowerCase(); + const code = shortCode + (region ? "-" + region : ""); + if (code === key) { console.log("-> Match", languageKey, "->", id); return id; @@ -46,8 +49,7 @@ function mapLanguageCodeToId(languageKey) { // If none found, try to find a better alternative by using the base language at least for (const id in LANGUAGES) { const data = LANGUAGES[id]; - const code = data.code.toLowerCase(); - const shortCode = code.split("-")[0]; + const shortCode = data.code.toLowerCase(); if (shortCode === key) { console.log("-> Desperate Match", languageKey, "->", id);