keycloak-scim/js/apps/account-ui/src/i18n.ts
Erik Jan de Wit 5897334ddb
Align environment variables between consoles (#30125)
* change to make authServerUrl the same as authUrl

fixes: #29641
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>

* Remove `authUrl` entirely

Signed-off-by: Jon Koops <jonkoops@gmail.com>

* Remove file that is unrelated

Signed-off-by: Jon Koops <jonkoops@gmail.com>

* Split out and align environment variables between consoles

Signed-off-by: Jon Koops <jonkoops@gmail.com>

* Restore removed variables to preserve backwards compatibility

Signed-off-by: Jon Koops <jonkoops@gmail.com>

* Also deprecate the `authUrl` for the Admin Console

Signed-off-by: Jon Koops <jonkoops@gmail.com>

---------

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Jon Koops <jonkoops@gmail.com>
Co-authored-by: Jon Koops <jonkoops@gmail.com>
2024-06-06 08:36:46 +02:00

47 lines
1.3 KiB
TypeScript

import { LanguageDetectorModule, createInstance } from "i18next";
import HttpBackend from "i18next-http-backend";
import { initReactI18next } from "react-i18next";
import { environment } from "./environment";
import { joinPath } from "./utils/joinPath";
const DEFAULT_LOCALE = "en";
type KeyValue = { key: string; value: string };
// This type is aliased to any, so that we can find all the places where we use it.
// In the future all casts to this type should be removed from the code, so
// that we can have a proper type-safe translation function.
export type TFuncKey = any;
export const keycloakLanguageDetector: LanguageDetectorModule = {
type: "languageDetector",
detect() {
return environment.locale;
},
};
export const i18n = createInstance({
fallbackLng: DEFAULT_LOCALE,
interpolation: {
escapeValue: false,
},
backend: {
loadPath: joinPath(
environment.authServerUrl,
`resources/${environment.realm}/account/{{lng}}`,
),
parse: (data: string) => {
const messages = JSON.parse(data);
const result: Record<string, string> = {};
messages.forEach((v: KeyValue) => (result[v.key] = v.value));
return result;
},
},
});
i18n.use(HttpBackend);
i18n.use(keycloakLanguageDetector);
i18n.use(initReactI18next);