web/admin: only check first half of locale when detecting

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>

#2178
This commit is contained in:
Jens Langhammer 2022-01-28 12:35:37 +01:00
parent 8b22e7bcc3
commit b5b5a9eed3

View file

@ -29,7 +29,7 @@ export const LOCALES: {
locale: localeDEBUG, locale: localeDEBUG,
}, },
{ {
code: "fr_FR", code: "fr",
plurals: fr, plurals: fr,
label: t`French`, label: t`French`,
locale: localeFR_FR, locale: localeFR_FR,
@ -50,9 +50,13 @@ LOCALES.forEach((locale) => {
const DEFAULT_FALLBACK = () => "en"; const DEFAULT_FALLBACK = () => "en";
export function autoDetectLanguage() { export function autoDetectLanguage() {
const detected = let detected =
detect(fromUrl("lang"), fromStorage("lang"), fromNavigator(), DEFAULT_FALLBACK) || detect(fromUrl("lang"), fromStorage("lang"), fromNavigator(), DEFAULT_FALLBACK) ||
DEFAULT_FALLBACK(); DEFAULT_FALLBACK();
// For now we only care about the first locale part
if (detected.includes("_")) {
detected = detected.split("_")[0];
}
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);