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 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
|
@ -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}'`);
|
||||
}
|
||||
|
|
Reference in a new issue