{"id":21822063,"url":"https://github.com/stevensacks/storybook-react-intl","last_synced_at":"2025-04-02T21:12:18.192Z","repository":{"id":45497767,"uuid":"385220293","full_name":"stevensacks/storybook-react-intl","owner":"stevensacks","description":"react-intl addon for Storybook","archived":false,"fork":false,"pushed_at":"2025-01-20T06:44:53.000Z","size":2637,"stargazers_count":10,"open_issues_count":0,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T06:11:58.748Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevensacks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-12T11:13:55.000Z","updated_at":"2025-03-30T00:48:16.000Z","dependencies_parsed_at":"2024-10-08T13:46:08.949Z","dependency_job_id":"30ed2e7f-9ec2-45cc-8aad-d8a469944cc8","html_url":"https://github.com/stevensacks/storybook-react-intl","commit_stats":{"total_commits":104,"total_committers":18,"mean_commits":5.777777777777778,"dds":0.3076923076923077,"last_synced_commit":"26a9e1c06b518253a18773486bcf6a466f75476d"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":"storybookjs/addon-kit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevensacks%2Fstorybook-react-intl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevensacks%2Fstorybook-react-intl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevensacks%2Fstorybook-react-intl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevensacks%2Fstorybook-react-intl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevensacks","download_url":"https://codeload.github.com/stevensacks/storybook-react-intl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246763945,"owners_count":20829799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-27T17:12:51.671Z","updated_at":"2025-04-02T21:12:18.156Z","avatar_url":"https://github.com/stevensacks.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Storybook react-intl addon\n\nAdd react-intl support to Storybook.\n\nRequired Versions:\n\nv3.1.x\n* storybook - `^8.2.0`\n* react-intl - `^5.24.0 || ^6.0.0`\n\nv3.0.x\n* storybook - `^8.0.0`\n* react-intl - `^5.24.0 || ^6.0.0`\n\nThis Storybook addon assumes your project is already set up with [react-intl](https://formatjs.io/docs/react-intl/), and that it is properly configured and working.\n\n## Installation\n\nThis addon should be added as a dev dependency.\n\n```bash\nnpm i -D storybook-react-intl\n```\n\n```bash\nyarn add -D storybook-react-intl\n```\n\nYou will need to install `react-intl` as a dependency of your project if it is not already installed.\n```bash\nnpm i -S react-intl\n```\n\n```bash\nyarn add react-intl\n```\n\n## Usage\n\nAfter installing, follow these steps to enable this addon in Storybook.\n\n### main.ts\nInsert this addon into your addons array:\n```typescript\n{\n  addons: [\n    // other addons...\n    'storybook-react-intl',\n  ]\n}\n```\n---\n\n### reactIntl.ts\nCreate a file in your `.storybook` folder called `reactIntl.ts` (or whatever you like). This is where you will set up your react-intl configuration.\n\nIn this file, copy and paste the below code and make whatever modifications you need.\n```typescript\nconst locales = ['en', 'de'];\n\nconst messages = locales.reduce((acc, lang) =\u003e ({\n  ...acc,\n  [lang]: require(`../locale/${lang}.json`), // whatever the relative path to your messages json is\n}), {});\n\nconst formats = {}; // optional, if you have any formats\n\nexport const reactIntl = {\n  defaultLocale: 'en',\n  locales,\n  messages,\n  formats,\n  timeZone: 'America/New_York', // optional, specify a time zone\n};\n```\n---\n\n### preview.ts\nIn your `preview.ts`, you need to add the `locales` and `locale` to `initialGlobals` (or `globals` if you're not using storybook 8.2+), as well as add `reactIntl` that you exported from the above file to parameters.\n\n`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.\n\n`locale` is the default locale, which can be read from `reactIntl` or set manually if you choose.\n\n```typescript\nimport {reactIntl} from './reactIntl';\n\nconst preview: Preview = {\n    initialGlobals: {\n        locale: reactIntl.defaultLocale,\n        locales: {\n            en: 'English',\n            de: 'Deutsche',  \n        },\n    },\n    parameters: {\n        reactIntl,\n    }\n};\n\nexport default preview;\n```\n\nYou can also set locales to Storybook compatible objects as [documented in the storybook-i18n](https://github.com/stevensacks/storybook-i18n#end-users) addon (which is included as part of this addon).\n\n```javascript\nimport {reactIntl} from './reactIntl';\n\nconst preview: Preview = {\n    initialGlobals: {\n        locale: reactIntl.defaultLocale,\n        locales: {\n            en: {icon: '🇺🇸', title: 'English', right: 'EN'},\n            fr: {icon: '🇫🇷', title: 'Français', right: 'FR'},\n            ja: {icon: '🇯🇵', title: '日本語', right: 'JP'},\n        },\n    },\n    parameters: {\n        reactIntl,\n    }\n};\n\nexport default preview;\n```\n\n## Story Parameters Locale\n\nIf you want to have a story use a specific locale, set it in that Story's parameters.\n\n```typescript jsx\nexport const Default: StoryObj = {\n    render: () =\u003e \u003cYourComponent/\u003e,\n};\n\nexport const Japanese: StoryObj = {\n    parameters: {\n        locale: 'ja',\n    },\n    render: () =\u003e \u003cYourComponent/\u003e,\n};\n```\nNote 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.\n\nIn the above example, if you view the Japanese story and then click back on the Default story, the locale will stay `ja`.\n\n---\nOnce you have finished these steps and launch storybook, you should see a globe icon in the toolbar.\n\nClicking this globe icon will show a dropdown with the locales you defined.\n\nSwitching locales will use the strings defined in your messages.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevensacks%2Fstorybook-react-intl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevensacks%2Fstorybook-react-intl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevensacks%2Fstorybook-react-intl/lists"}