From f02af23dd7f478a86c0522d1f4c3d924df06f3f0 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 12 Apr 2021 16:21:53 +0200 Subject: site: fix locale detection (it mistakenly set the locale to undefined before) --- site/i18n.js | 12 ++++++++---- site/index.html | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/site/i18n.js b/site/i18n.js index 5f882c5..829373e 100644 --- a/site/i18n.js +++ b/site/i18n.js @@ -54,12 +54,16 @@ let locale = "en"; // is found, it returns the key as a fallback value // (therefore, keys should themselves be understandable texts) export function _(key) { - return !(locale in langs) ? key - : !(key in langs[locale]) ? key - : langs[locale][key] + if (!(locale in langs) ? false : (key in langs[locale])) { + return langs[locale][key]; + } else { + console.log("missing translation for lang, key:", locale, key); + return key; + } } export function setLang (loc) { + console.log("set lang to", loc); locale = loc; } @@ -69,7 +73,7 @@ export function setLang (loc) { export function tryBrowserDefaultLang () { let guess = navigator.language; if (guess in langs) { - setLang(lang); + setLang(guess); } else { for (var lang of navigator.languages) { if (lang in langs) { diff --git a/site/index.html b/site/index.html index c2ac9c9..4034787 100644 --- a/site/index.html +++ b/site/index.html @@ -251,7 +251,7 @@ mkElement("p", msg, "error"), appendChildren( mkElement("p",_("attempted path:"),"error"), - [mkElement("tt", surveyUrl,"error")] + [mkElement("tt"," "+surveyUrl,"error")] ) ]); } -- cgit v1.2.3