Gathering detailed insights and metrics for storybook-react-i18next
Gathering detailed insights and metrics for storybook-react-i18next
Gathering detailed insights and metrics for storybook-react-i18next
Gathering detailed insights and metrics for storybook-react-i18next
npm install storybook-react-i18next
Typescript
Module System
Node Version
NPM Version
TypeScript (64.84%)
JavaScript (34.85%)
HTML (0.31%)
Total Downloads
13,972,468
Last Day
19,639
Last Week
109,791
Last Month
491,227
Last Year
5,241,319
MIT License
22 Stars
203 Commits
13 Forks
2 Watchers
1 Branches
6 Contributors
Updated on May 04, 2025
Latest Version
4.0.1
Package Id
storybook-react-i18next@4.0.1
Unpacked Size
74.03 kB
Size
15.32 kB
File Count
21
NPM Version
10.8.2
Node Version
20.19.1
Published on
May 04, 2025
Cumulative downloads
Total Downloads
Last Day
45.3%
19,639
Compared to previous day
Last Week
4.7%
109,791
Compared to previous week
Last Month
-14.3%
491,227
Compared to previous month
Last Year
5.3%
5,241,319
Compared to previous year
1
Easy react-i18next Storybook integration.
Required Peer Dependencies:
Version 4.x - storybook - ^9.0.0
Version 3.x - storybook - ^8.0.0
i18next - ^22.0.0 || ^23.0.0 || ^24.0.0 || ^25.0.0
i18next-browser-languagedetector - ^7.0.0 || ^8.0.0
i18next-http-backend: ^2.0.0 || ^3.0.0
react-i18next - ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0
This Storybook addon assumes your project is already set up with i18next and react-i18next, with all the required packages installed, and that it is properly configured and working.
Install this addon as a devDependency.
1npm i -D storybook-react-i18next
You will need to install i18next
and react-i18next
as dependencies to your project if they are not already installed.
1npm i -S i18next react-i18next i18next-browser-languagedetector i18next-http-backend
After installing, follow these 3 steps to enable this addon in Storybook.
Insert this addon into your addons array:
1{ 2 addons: [ 3 // other addons... 4 'storybook-react-i18next', 5 ] 6}
Create a file in your .storybook
folder called i18next.ts
(or whatever you like).
In this file, copy and paste the below code and make whatever modifications you need (paths to resource files, languages, etc.).
1import {initReactI18next} from 'react-i18next'; 2import i18n from 'i18next'; 3import Backend from 'i18next-http-backend'; 4import LanguageDetector from 'i18next-browser-languagedetector'; 5 6const ns = ['common']; 7const supportedLngs = ['en', 'fr', 'ja']; 8const resources = ns.reduce((acc, n) => { 9 supportedLngs.forEach((lng) => { 10 if (!acc[lng]) acc[lng] = {}; 11 acc[lng] = { 12 ...acc[lng], 13 [n]: require(`../public/locales/${lng}/${n}.json`), 14 }; 15 }); 16 return acc; 17}, {}); 18 19i18n.use(initReactI18next) 20 .use(LanguageDetector) 21 .use(Backend) 22 .init({ 23 //debug: true, 24 lng: 'en', 25 fallbackLng: 'en', 26 defaultNS: 'common', 27 ns, 28 interpolation: {escapeValue: false}, 29 react: {useSuspense: false}, 30 supportedLngs, 31 resources, 32 }); 33 34export default i18n;
Refer to the i18next Configuration Options documentation for detailed information about the configuration options.
In your preview.ts
, you need to add the locales
and locale
to initialGlobals
(or globals
if you're not using the latest version of storybook), as well as adding i18n
that you exported from the above file to parameters.
locales
is an object where the keys are the "ids" of the locales/languages and the values are the names you want to display in the dropdown.
locale
is what you want the default locale to be.
1import i18n from './i18next'; 2 3const preview: Preview = { 4 initialGlobals: { 5 locale: 'en', 6 locales: { 7 en: 'English', 8 fr: 'Français', 9 ja: '日本語', 10 }, 11 }, 12 parameters: { 13 i18n, 14 }, 15}; 16 17export default preview;
You can also use full locale strings as keys. It depends on your i18next configuration.
1import i18n from './i18next'; 2 3const preview: Preview = { 4 initialGlobals: { 5 locale: 'en_US', 6 locales: { 7 en_US: 'English (US)', 8 en_GB: 'English (GB)', 9 fr_FR: 'Français', 10 ja_JP: '日本語', 11 }, 12 }, 13 parameters: { 14 i18n, 15 }, 16}; 17 18export default preview;
The locales
object can also have values as an object with keys of title
, left
, or right
.
This is useful if you want to include an emoji flag or some other string to the left or right side.
For example:
1import i18n from './i18next'; 2 3const preview: Preview = { 4 initialGlobals: { 5 locale: "en", 6 locales: { 7 en: {icon: '🇺🇸', title: 'English', right: 'EN'}, 8 fr: {icon: '🇫🇷', title: 'Français', right: 'FR'}, 9 ja: {icon: '🇯🇵', title: '日本語', right: 'JP'}, 10 }, 11 }, 12 parameters: { 13 i18n, 14 }, 15}; 16 17export default preview;
Or something like this:
1import i18n from './i18next'; 2 3const preview: Preview = { 4 initialGlobals: { 5 locale: 'en_US', 6 locales: { 7 en_US: {title: 'English', right: 'US'}, 8 en_GB: {title: 'English', right: 'GB'}, 9 fr_FR: {title: 'Français', right: 'FR'}, 10 ja_JP: {title: '日本語', right: 'JP'}, 11 }, 12 }, 13 parameters: { 14 i18n, 15 }, 16}; 17 18export default preview;
If you want to have a story use a specific locale, set it in that Story's parameters.
1export const Default: StoryObj = { 2 render: () => <YourComponent/>, 3}; 4 5export const Japanese: StoryObj = { 6 parameters: { 7 locale: 'ja', 8 }, 9 render: () => <YourComponent/>, 10};
Note that doing this switches the current locale to the parameter one, so when you change to a story without a parameter, it will stay at the last selected locale.
In the above example, if you view the Japanese story and then click back on the Default story, the locale will stay ja
.
Once you have finished these steps and launch storybook, you should see a globe icon in the toolbar.
Clicking this globe icon will show a dropdown with the locales you defined in parameters
.
Switching locales will use the strings defined in your locale json files.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More