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() {
|
||||||
|
const detected =
|
||||||
detect(fromUrl("lang"), fromStorage("lang"), fromNavigator(), DEFAULT_FALLBACK) ||
|
detect(fromUrl("lang"), fromStorage("lang"), fromNavigator(), DEFAULT_FALLBACK) ||
|
||||||
DEFAULT_FALLBACK();
|
DEFAULT_FALLBACK();
|
||||||
if (detected in i18n._messages) {
|
if (detected in i18n._messages) {
|
||||||
console.debug(`authentik/locale: Activating detected locale '${detected}'`);
|
console.debug(`authentik/locale: Activating detected locale '${detected}'`);
|
||||||
i18n.activate(detected);
|
i18n.activate(detected);
|
||||||
} else {
|
} else {
|
||||||
console.debug(`authentik/locale: No locale for '${detected}', falling back to en`);
|
console.debug(`authentik/locale: No locale for '${detected}', falling back to en`);
|
||||||
i18n.activate(DEFAULT_FALLBACK());
|
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 New Issue