2021-10-01 12:06:32 +00:00
|
|
|
import { en, fr } from "make-plural/plurals";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
|
|
|
import { i18n } from "@lingui/core";
|
2021-10-28 07:48:51 +00:00
|
|
|
import { detect, fromNavigator, fromStorage, fromUrl } from "@lingui/detect-locale";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-04-03 17:26:43 +00:00
|
|
|
import { messages as localeEN } from "../locales/en";
|
2021-10-01 12:06:32 +00:00
|
|
|
import { messages as localeFR_FR } from "../locales/fr_FR";
|
2021-04-03 18:34:16 +00:00
|
|
|
import { messages as localeDEBUG } from "../locales/pseudo-LOCALE";
|
2021-04-03 17:07:11 +00:00
|
|
|
|
2021-04-03 18:34:16 +00:00
|
|
|
i18n.loadLocaleData("en", { plurals: en });
|
|
|
|
i18n.loadLocaleData("debug", { plurals: en });
|
2021-10-01 12:06:32 +00:00
|
|
|
i18n.loadLocaleData("fr_FR", { plurals: fr });
|
2021-04-03 17:26:43 +00:00
|
|
|
i18n.load("en", localeEN);
|
2021-10-01 12:06:32 +00:00
|
|
|
i18n.load("fr_FR", localeFR_FR);
|
2021-04-03 18:34:16 +00:00
|
|
|
i18n.load("debug", localeDEBUG);
|
2021-04-03 17:59:22 +00:00
|
|
|
|
2021-10-01 12:06:32 +00:00
|
|
|
const DEFAULT_FALLBACK = () => "en";
|
|
|
|
|
2021-10-05 14:23:40 +00:00
|
|
|
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());
|
|
|
|
}
|