INNER CODE UNIT · TypeScript
resolveSupportedLocale
Cosmian/kms · ui/src/i18n/index.ts:14
const resolveSupportedLocale = (lng: string): SupportedLocale =>
SUPPORTED_LOCALES.find((locale) => locale !== "en" && LOCALE_REGISTRY[locale].matches(lng)) ?? "en";
i18n.use(LanguageDetector)
.use(initReactI18next)
.init({
resources: Object.fromEntries(SUPPORTED_LOCALES.map((locale) => [locale, LOCALE_REGISTRY[locale].resources])),
fallbackLng: "en",
supportedLngs: [...SUPPORTED_LOCALES],
load: "all",
detection: {
// Prefer an explicit user choice, then the browser language.
order: ["localStorage", "navigator"],
caches: ["localStorage"],
lookupLocalStorage: LOCALE_STORAGE_KEY,
// Normalise every detected locale to one of the supported bundles.
convertDetectedLanguage: resolveSupportedLocale,
},