made realm the namespace so we can change the bundle (#30239)

fixes: #29566

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-06-24 10:00:09 +02:00 committed by GitHub
parent 13ef6fb1c8
commit 3156f264b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 6 deletions

View file

@ -1,13 +1,14 @@
import { PropsWithChildren, useEffect, useMemo, useState } from "react";
import { useMatch } from "react-router-dom";
import RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
import {
createNamedContext,
useEnvironment,
useRequiredContext,
} from "@keycloak/keycloak-ui-shared";
import { PropsWithChildren, useEffect, useMemo, useState } from "react";
import { useMatch } from "react-router-dom";
import { useAdminClient } from "../../admin-client";
import { DashboardRouteWithRealm } from "../../dashboard/routes/Dashboard";
import RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
import { i18n } from "../../i18n/i18n";
import { useFetch } from "../../utils/useFetch";
type RealmContextType = {
@ -41,7 +42,13 @@ export const RealmContextProvider = ({ children }: PropsWithChildren) => {
);
// Configure admin client to use selected realm when it changes.
useEffect(() => adminClient.setConfig({ realmName: realm }), [realm]);
useEffect(() => {
(async () => {
adminClient.setConfig({ realmName: realm });
await i18n.loadNamespaces(realm);
i18n.setDefaultNamespace(realm);
})();
}, [realm]);
useFetch(
() => adminClient.realms.findOne({ realm }),
setRealmRepresentation,

View file

@ -16,10 +16,12 @@ export const i18n = createInstance({
interpolation: {
escapeValue: false,
},
defaultNS: [environment.realm],
ns: [environment.realm],
backend: {
loadPath: joinPath(
environment.adminBaseUrl,
`resources/${environment.realm}/admin/{{lng}}`,
`resources/{{ns}}/admin/{{lng}}`,
),
parse: (data: string) => {
const messages = JSON.parse(data);

View file

@ -241,7 +241,7 @@ export const RealmOverrides = ({
try {
for (const key of selectedRowKeys) {
delete (
i18n.store.data[whoAmI.getLocale()]["translation"] as Record<
i18n.store.data[whoAmI.getLocale()][currentRealm] as Record<
string,
string
>