From cde303e78099a944f34ac757298c0c400ac64118 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 5 Oct 2021 16:23:40 +0200 Subject: [PATCH] web: fix strings not being translated at all when matching browser locale not found Signed-off-by: Jens Langhammer # Conflicts: # web/src/interfaces/locale.ts --- web/src/interfaces/locale.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/web/src/interfaces/locale.ts b/web/src/interfaces/locale.ts index cfb1ab476..73c0acc56 100644 --- a/web/src/interfaces/locale.ts +++ b/web/src/interfaces/locale.ts @@ -11,6 +11,15 @@ i18n.load("en", localeEN); i18n.load("debug", localeDEBUG); i18n.activate("en"); -if (window.location.search.includes("debugLocale")) { - i18n.activate("debug"); +const DEFAULT_FALLBACK = () => "en"; + +const detected = + detect(fromUrl("lang"), fromStorage("lang"), fromNavigator(), DEFAULT_FALLBACK) || + DEFAULT_FALLBACK(); +if (detected in i18n._messages) { + console.debug(`authentik/locale: Activating detected locale '${detected}'`); + i18n.activate(detected); +} else { + console.debug(`authentik/locale: No locale for '${detected}', falling back to en`); + i18n.activate(DEFAULT_FALLBACK()); }