How to integrate with Storybook? #2591
-
Hi there! 👋 I'm on a mission to integrate the Paraglide JS with Storybook in our project. Let me give a quick preview on our architecture setup firstly. We have a monorepo, and we have two front-end applications:
So, how I attempted so far to make it work:
And on the second point is where I am stuck. Is there any better way to attempt at integrating it? If so, I would appreciate if someone could point me in the right direction. 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Actually, I think I've figured it out. There's no need to use With the following code: // .storybook/main.ts
import type { Decorator, Preview } from "@storybook/svelte";
import i18n from "storybook-i18n/preview";
import { type AvailableLanguageTag } from "path/to/your/paraglide/runtime.js";
import I18nProvider from "path/to/your/provider/I18nProvider.svelte";
// @ts-ignore
const decorators = i18n?.decorators || [];
export const globals = {
locale: "en",
locales: {
en: "English",
"zh-TW": "Mandarin (Taiwan)",
pl: "Polish",
} satisfies Record<AvailableLanguageTag, string>,
};
export const decorators: Decorator[] = [
...decorators,
(Story, context) => ({
Component: I18nProvider,
props: {
locale: context.globals["locale"],
},
}),
];
export const preview: Preview = {
...i18n,
decorators,
globals,
parameters,
}; And then, the custom provider: <script lang="ts">
// I18nProvider.svelte
import {
setLanguageTag,
onSetLanguageTag,
type AvailableLanguageTag,
} from "../../../libs/i18n/src/runtime.js";
export let locale: AvailableLanguageTag = "en";
onSetLanguageTag((lang) => {
window.document.documentElement.lang = lang;
});
$: {
setLanguageTag(locale);
}
</script>
{#key locale}
<slot />
{/key} It almost works, except that the updated locale is not passed down to the components. The UI components when using a call to EDIT. Silly me, I wasn't using the same path to runtime on both sides, it works now. |
Beta Was this translation helpful? Give feedback.
Actually, I think I've figured it out. There's no need to use
@storybook/manager-api
.With the following code: