From 64c8b0c8f11cce371517f752ee20ef1c3ae730ef Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Thu, 25 Oct 2018 21:34:52 +0200 Subject: [PATCH] feat(i18n): add i18n support to storybook --- .storybook/addons.js | 1 + .storybook/config.js | 19 ++++++++++++++++++- app/containers/Root.js | 2 +- package.json | 1 + yarn.lock | 9 ++++++++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.storybook/addons.js b/.storybook/addons.js index df881d45..babce72d 100644 --- a/.storybook/addons.js +++ b/.storybook/addons.js @@ -4,3 +4,4 @@ import 'storybook-addon-styled-component-theme/dist/register' import '@storybook/addon-storysource/register' import '@storybook/addon-links/register' import '@storybook/addon-console' +import 'storybook-addon-intl/register' diff --git a/.storybook/config.js b/.storybook/config.js index d839cbf1..bb05bdf0 100644 --- a/.storybook/config.js +++ b/.storybook/config.js @@ -5,13 +5,27 @@ import { withOptions } from '@storybook/addon-options' import { setDefaults, withInfo } from '@storybook/addon-info' import { withConsole } from '@storybook/addon-console' import { linkTo } from '@storybook/addon-links' +import { setIntlConfig, withIntl } from 'storybook-addon-intl' import chaptersAddon from 'react-storybook-addon-chapters' import StoryRouter from 'storybook-react-router' import { dark, light } from 'themes' - +import { getDefaultLocale, locales } from 'lib/i18n' import React from 'react' import GlobalStyle from 'components/UI/GlobalStyle' +// Register supported locales. +import '../app/lib/i18n/locale' + +// Get translations. +import translations from '../app/lib/i18n/translation' + +// Set intl configuration +setIntlConfig({ + locales: locales, + defaultLocale: getDefaultLocale(), + getMessages: locale => translations[locale] +}) + // Info addDecorator( withInfo({ @@ -25,6 +39,9 @@ addDecorator( }) ) +// Intl +addDecorator(withIntl) + // Router addDecorator(StoryRouter({})) diff --git a/app/containers/Root.js b/app/containers/Root.js index 6eb0262c..3429d789 100644 --- a/app/containers/Root.js +++ b/app/containers/Root.js @@ -70,10 +70,10 @@ class Root extends React.Component { // If this is the first time the app has mounted, initialise things. if (!isMounted) { + setMounted(true) initTheme() initLocale() initCurrency() - setMounted(true) } // Hide the loading screen after a set time. diff --git a/package.json b/package.json index 6384d034..4341c39b 100644 --- a/package.json +++ b/package.json @@ -284,6 +284,7 @@ "rimraf": "^2.6.2", "sass-loader": "^7.1.0", "spectron": "^4.0.0", + "storybook-addon-intl": "^2.3.1", "storybook-addon-styled-component-theme": "^1.0.7", "storybook-react-router": "^1.0.1", "style-loader": "^0.23.1", diff --git a/yarn.lock b/yarn.lock index 5f0362ea..a1c6226f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13278,7 +13278,7 @@ promzard@^0.3.0: dependencies: read "1" -prop-types@15.x, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.8, prop-types@^15.5.9, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2: +prop-types@15.x, prop-types@^15.5.0, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.8, prop-types@^15.5.9, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2: version "15.6.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102" integrity sha512-3pboPvLiWD7dkI3qf3KbUe6hKFKa52w+AE0VCqECtf+QHAKgOL37tTaNCnuX1nAAQ4ZhyP+kYVKf8rLmJ/feDQ== @@ -15631,6 +15631,13 @@ stealthy-require@^1.1.0: resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b" integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks= +storybook-addon-intl@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/storybook-addon-intl/-/storybook-addon-intl-2.3.1.tgz#d333ab452026811bb8932708d6ff07d8a318821d" + integrity sha512-G9c7eD1BuuOwc9F/RvAWSisxHQVrA2fCef6WhcvDwPyX6b0RuMLO9dEMABI2DFkLbkXhlXiZy0qdr9UZxEhH0A== + dependencies: + prop-types "^15.5.0" + storybook-addon-styled-component-theme@^1.0.7: version "1.0.7" resolved "https://registry.yarnpkg.com/storybook-addon-styled-component-theme/-/storybook-addon-styled-component-theme-1.0.7.tgz#8126497f69e734212395e60aad68efa11d3c6fe5"