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:
parent
776f3f69a5
commit
ab17a12184
|
@ -49,13 +49,16 @@ LOCALES.forEach((locale) => {
|
||||||
|
|
||||||
const DEFAULT_FALLBACK = () => "en";
|
const DEFAULT_FALLBACK = () => "en";
|
||||||
|
|
||||||
const detected =
|
export function autoDetectLanguage() {
|
||||||
detect(fromUrl("lang"), fromStorage("lang"), fromNavigator(), DEFAULT_FALLBACK) ||
|
const detected =
|
||||||
DEFAULT_FALLBACK();
|
detect(fromUrl("lang"), fromStorage("lang"), fromNavigator(), DEFAULT_FALLBACK) ||
|
||||||
if (detected in i18n._messages) {
|
DEFAULT_FALLBACK();
|
||||||
console.debug(`authentik/locale: Activating detected locale '${detected}'`);
|
if (detected in i18n._messages) {
|
||||||
i18n.activate(detected);
|
console.debug(`authentik/locale: Activating detected locale '${detected}'`);
|
||||||
} else {
|
i18n.activate(detected);
|
||||||
console.debug(`authentik/locale: No locale for '${detected}', falling back to en`);
|
} else {
|
||||||
i18n.activate(DEFAULT_FALLBACK());
|
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
|
@ -16,7 +16,7 @@ import "../../../elements/forms/Form";
|
||||||
import "../../../elements/forms/FormElement";
|
import "../../../elements/forms/FormElement";
|
||||||
import "../../../elements/forms/HorizontalFormElement";
|
import "../../../elements/forms/HorizontalFormElement";
|
||||||
import { ModelForm } from "../../../elements/forms/ModelForm";
|
import { ModelForm } from "../../../elements/forms/ModelForm";
|
||||||
import { LOCALES } from "../../../interfaces/locale";
|
import { LOCALES, autoDetectLanguage } from "../../../interfaces/locale";
|
||||||
|
|
||||||
@customElement("ak-user-details-form")
|
@customElement("ak-user-details-form")
|
||||||
export class UserDetailsForm extends ModelForm<UserSelf, number> {
|
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);
|
const newLocale = LOCALES.find((locale) => locale.code === newConfig.locale);
|
||||||
if (newLocale) {
|
if (newLocale) {
|
||||||
i18n.activate(newLocale.code);
|
i18n.activate(newLocale.code);
|
||||||
|
} else if (newConfig.locale === "") {
|
||||||
|
autoDetectLanguage();
|
||||||
} else {
|
} else {
|
||||||
console.debug(`authentik/user: invalid locale: '${newConfig.locale}'`);
|
console.debug(`authentik/user: invalid locale: '${newConfig.locale}'`);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue