web/user: fix auto-detected locale not being re-activated when switching to auto-detect

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer
2022-01-02 20:01:44 +01:00
parent 776f3f69a5
commit ab17a12184
3 changed files with 709 additions and 1203 deletions

View File

@ -49,13 +49,16 @@ LOCALES.forEach((locale) => {
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());
export function autoDetectLanguage() {
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());
}
}
autoDetectLanguage();