storybook-i18n
Version:
Tool to set the locale in Storybook for i18n
1 lines • 1.57 kB
Source Map (JSON)
{"version":3,"sources":["../src/withLocale.ts","../src/preview.ts"],"names":["withLocale","story","context","_","updateGlobals","useGlobals","useEffect","locale","preview","preview_default"],"mappings":"6DAOO,IAAMA,CAAa,CAAA,CACtBC,CACAC,CAAAA,CAAAA,GACC,CACD,GAAM,CAACC,CAAAA,CAAGC,CAAa,CAAA,CAAIC,qBAAW,EAAA,CAEtC,OAAAC,oBAAAA,CAAU,IAAM,CACZ,GAAM,CACF,UAAY,CAAA,CAAC,MAAAC,CAAAA,CAAM,CACvB,CAAIL,CAAAA,CAAAA,CAEAK,CACAH,EAAAA,CAAAA,CAAc,CAAC,MAAA,CAAAG,CAAM,CAAC,EAE9B,CAAA,CAAG,EAAE,CAEEN,CAAAA,CAAAA,CAAMC,CAAO,CACxB,CCrBA,CAAA,IAAMM,CAAwC,CAAA,CAC1C,UAAY,CAAA,CAACR,CAAU,CAAA,CACvB,cAAgB,CAAA,CACZ,MAAQ,CAAA,EAAA,CACR,OAAS,CAAA,EACb,CACJ,EAEOS,CAAQD,CAAAA","file":"preview.cjs","sourcesContent":["import {useEffect, useGlobals} from 'storybook/preview-api';\nimport type {\n PartialStoryFn as StoryFunction,\n Renderer,\n StoryContext,\n} from 'storybook/internal/types';\n\nexport const withLocale = (\n story: StoryFunction<Renderer>,\n context: StoryContext,\n) => {\n const [_, updateGlobals] = useGlobals();\n\n useEffect(() => {\n const {\n parameters: {locale},\n } = context;\n\n if (locale) {\n updateGlobals({locale});\n }\n }, []);\n\n return story(context);\n};\n","import type {Renderer, ProjectAnnotations} from 'storybook/internal/types';\nimport {withLocale} from './withLocale';\n\nconst preview: ProjectAnnotations<Renderer> = {\n decorators: [withLocale],\n initialGlobals: {\n locale: '',\n locales: {},\n },\n};\n\nexport default preview;\n"]}