Skip to content

Commit

Permalink
fix(storybook): intl setup (#2163)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenko authored Apr 5, 2022
1 parent 3da28eb commit 53fa7e9
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions docs/.storybook/configs/intl-context.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import PropTypes from 'prop-types';
import { IntlProvider } from 'react-intl';
import * as messages from '../../../packages/i18n';

const locales = Object.keys(messages);
const locales = ['en', 'de', 'es', 'fr-FR', 'ja', 'zh-CN'];

const slugifyLocale = (locale) => {
const getMessagesForLocale = (locale) => {
switch (locale) {
case 'frFR':
return 'fr-FR';
case 'zhCN':
return 'zh-CN';
case 'en':
return require('../../../packages/i18n/data/en.json');
case 'es':
return require('../../../packages/i18n/data/es.json');
case 'de':
return require('../../../packages/i18n/data/de.json');
case 'fr-FR':
return require('../../../packages/i18n/data/fr-FR.json');
case 'zh-CN':
return require('../../../packages/i18n/data/zh-CN.json');
case 'ja':
return require('../../../packages/i18n/data/ja.json');
default:
return locale;
throw new Error(`Unable to load messages for locale ${locale}.`);
}
};

Expand All @@ -23,9 +30,9 @@ const namifyLocale = (locale) => {
return 'Español';
case 'de':
return 'Deutsch';
case 'frFR':
case 'fr-FR':
return 'Français';
case 'zhCN':
case 'zh-CN':
return '简化字';
case 'ja':
return '日本人';
Expand All @@ -36,8 +43,9 @@ const namifyLocale = (locale) => {

const IntlWrapper = (props) => {
const locale = props.locale;
const messages = getMessagesForLocale(locale);
return (
<IntlProvider locale={slugifyLocale(locale)} messages={messages[locale]}>
<IntlProvider locale={locale} messages={messages}>
{props.children}
</IntlProvider>
);
Expand Down

1 comment on commit 53fa7e9

@vercel
Copy link

@vercel vercel bot commented on 53fa7e9 Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.