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();

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,7 @@ import "../../../elements/forms/Form";
import "../../../elements/forms/FormElement";
import "../../../elements/forms/HorizontalFormElement";
import { ModelForm } from "../../../elements/forms/ModelForm";
import { LOCALES } from "../../../interfaces/locale";
import { LOCALES, autoDetectLanguage } from "../../../interfaces/locale";
@customElement("ak-user-details-form")
export class UserDetailsForm extends ModelForm<UserSelf, number> {
@ -42,6 +42,8 @@ export class UserDetailsForm extends ModelForm<UserSelf, number> {
const newLocale = LOCALES.find((locale) => locale.code === newConfig.locale);
if (newLocale) {
i18n.activate(newLocale.code);
} else if (newConfig.locale === "") {
autoDetectLanguage();
} else {
console.debug(`authentik/user: invalid locale: '${newConfig.locale}'`);
}