-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10234 from TylerAPfledderer/feat/storybook-react-…
…i18-addon feat(storybook): add storybook-react-i18next addon
- Loading branch information
Showing
11 changed files
with
178 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import i18n, { Resource } from "i18next" | ||
import { initReactI18next } from "gatsby-plugin-react-i18next" | ||
|
||
export const baseLocales = { | ||
en: { title: "English", left: "En" }, | ||
zh: { title: "中国人", left: "Zh" }, | ||
ru: { title: "Русский", left: "Ru" }, | ||
uk: { title: "українська", left: "Uk" }, | ||
} | ||
|
||
// Only i18n files named in this array are being exposed to Storybook. Add filenames as necessary. | ||
const ns = ["common", "page-about", "page-upgrades", "page-developers-index"] | ||
const supportedLngs = Object.keys(baseLocales) | ||
|
||
/** | ||
* Taking the ns array and combining all the ids | ||
* under a single ns per language, set to the default of "translation" | ||
*/ | ||
const resources: Resource = ns.reduce((acc, n) => { | ||
supportedLngs.forEach((lng) => { | ||
if (!acc[lng]) acc[lng] = {} | ||
acc[lng] = { | ||
translation: { | ||
...acc[lng].translation, | ||
...require(`../src/intl/${lng}/${n}.json`), | ||
}, | ||
} | ||
}) | ||
return acc | ||
}, {}) | ||
|
||
i18n.use(initReactI18next).init({ | ||
debug: true, | ||
fallbackLng: "en", | ||
interpolation: { escapeValue: false }, | ||
react: { useSuspense: false }, | ||
supportedLngs, | ||
resources, | ||
}) | ||
|
||
export default i18n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 15 additions & 23 deletions
38
src/components/BannerNotification/BannerNotification.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,27 @@ | ||
import { Meta, StoryObj } from "@storybook/react" | ||
import React from "react" | ||
import { Text } from "@chakra-ui/react" | ||
import { Meta, StoryFn } from "@storybook/react" | ||
import { useTranslation } from "react-i18next" | ||
import BannerNotification from "." | ||
|
||
export default { | ||
component: BannerNotification, | ||
args: { | ||
shouldShow: true, | ||
}, | ||
decorators: [(Story) => <Story />], | ||
} as Meta<typeof BannerNotification> | ||
|
||
/** | ||
* Story taken from PostMergeBanner component | ||
* and content from `../../content/developers/tutorials/hello-world-smart-contract-fullstack/index.md` | ||
*/ | ||
export const PostMergeBanner: StoryObj<typeof BannerNotification> = { | ||
args: { | ||
shouldShow: true, | ||
justify: "center", | ||
textAlign: "center", | ||
sx: { | ||
"& p": { | ||
maxWidth: "100ch", | ||
m: 0, | ||
p: 0, | ||
}, | ||
"& a": { | ||
textDecor: "underline", | ||
}, | ||
}, | ||
children: ( | ||
<p> | ||
This tutorial is out of date after the merge and may not work. Please | ||
raise a PR if you would like to contribute. | ||
</p> | ||
), | ||
}, | ||
export const PostMergeBanner: StoryFn<typeof BannerNotification> = (args) => { | ||
const { t } = useTranslation() | ||
|
||
return ( | ||
<BannerNotification {...args}> | ||
<Text m={0}>{t("page-upgrades-post-merge-banner-tutorial-ood")}</Text> | ||
</BannerNotification> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.