To preview your component in different languages, create separate stories for each language.
Example:
src/login/pages/Login.stories.tsx
import type { Meta, StoryObj } from "@storybook/react";
import { createKcPageStory } from "../KcPageStory";
const { KcPageStory } = createKcPageStory({ pageId: "login.ftl" });
const meta = {
title: "login/login.ftl",
component: KcPageStory
} satisfies Meta<typeof KcPageStory>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
render: () => <KcPageStory />
};
export const French: Story = {
render: ()=> (
<KcPageStory
kcContext={{
locale: {
currentLanguageTag: "fr"
}
}}
/>
)
};
export const Spanish: Story = {
render: ()=> (
<KcPageStory
kcContext={{
locale: {
currentLanguageTag: "es"
}
}}
/>
)
};
// Other stories ...
src/login/KcPageStory.tsx
export const { getKcContextMock } = createGetKcContextMock({
kcContextExtension,
kcContextExtensionPerPage,
overrides: {
locale: {
currentLanguageTag: "de",
},
},
overridesPerPage: {},
});
/* eslint-disable react-refresh/only-export-components */
import { createRoot } from "react-dom/client";
import { StrictMode } from "react";
import { KcPage } from "./kc.gen";
// The following block can be uncommented to test a specific page with `yarn dev`
// Don't forget to comment back or your bundle size will increase
import { getKcContextMock } from "./login/KcPageStory";
if (import.meta.env.DEV) {
window.kcContext = getKcContextMock({
pageId: "register.ftl",
overrides: {
locale: {
currentLanguageTag: "es"
}
}
});
}
createRoot(document.getElementById("root")!).render(
<StrictMode>
{!window.kcContext ? (
<h1>No Keycloak Context</h1>
) : (
<KcPage kcContext={window.kcContext} />
)}
</StrictMode>
);
Ok now let's see how to modify the base translation to best fit your usecase or create new translation messages: