Skip to content

Commit 667fefd

Browse files
authored
feat(i18n): support new locales fr-FR and zh-CN (#643)
1 parent 4cf0219 commit 667fefd

File tree

13 files changed

+40
-11
lines changed

13 files changed

+40
-11
lines changed

.storybook/decorators/intl/intl.js

+4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import { withKnobs, select } from '@storybook/addon-knobs/react';
44
import en from 'react-intl/locale-data/en';
55
import de from 'react-intl/locale-data/de';
66
import es from 'react-intl/locale-data/es';
7+
import frFR from 'react-intl/locale-data/fr';
8+
import zhCN from 'react-intl/locale-data/zh';
79
import * as messages from '../../../i18n';
810

911
addLocaleData(en);
1012
addLocaleData(de);
1113
addLocaleData(es);
14+
addLocaleData(frFR);
15+
addLocaleData(zhCN);
1216
const locales = Object.keys(messages);
1317

1418
export default storyFn => {

.storybook/webpack.config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const sourceFolders = [
1010
];
1111

1212
module.exports = ({ config }) => {
13-
config.plugins.push(new MomentLocalesPlugin({ localesToKeep: ['de', 'es'] }));
13+
config.plugins.push(
14+
new MomentLocalesPlugin({ localesToKeep: ['de', 'es', 'fr', 'zh-cn'] })
15+
);
1416
config.devtool = 'cheap-module-source-map'; // TODO: should we use something differen?
1517
config.module.rules = [
1618
// Disable require.ensure as it's not a standard language feature.

i18n/core.json i18n/data/core.json

File renamed without changes.

i18n/de.json i18n/data/de.json

File renamed without changes.

i18n/en.json i18n/data/en.json

File renamed without changes.

i18n/es.json i18n/data/es.json

File renamed without changes.

i18n/data/fr-FR.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

i18n/data/zh-CN.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

i18n/index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import en from './en.json';
2-
import de from './de.json';
3-
import es from './es.json';
1+
import en from './data/en.json';
2+
import de from './data/de.json';
3+
import es from './data/es.json';
4+
import frFR from './data/fr-FR.json';
5+
import zhCN from './data/zh-CN.json';
46

5-
export { en, de, es };
7+
export { en, de, es, frFR, zhCN };

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"start": "yarn storybook:start",
4646
"storybook:start": "start-storybook -p 9002 -s docs/assets",
4747
"docs:publish": "node scripts/publish-docs.js",
48-
"i18n:build": "node scripts/extract-intl.js --output-path=$(pwd)/i18n 'src/components/**/!(*.spec).js'",
48+
"i18n:build": "node scripts/extract-intl.js --output-path=$(pwd)/i18n/data 'src/components/**/!(*.spec).js'",
4949
"lint": "jest --projects jest.eslint.config.js",
5050
"lint:js": "jest --config jest.eslint.config.js",
5151
"format:js": "prettier --write '**/*.js'",

src/index.bundlespec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { i18n, customProperties } from 'ui-kit';
22

33
describe('exports', () => {
44
it('should export i18n for three languages', () => {
5-
expect(Object.keys(i18n)).toEqual(['en', 'de', 'es']);
5+
expect(Object.keys(i18n)).toEqual(['en', 'de', 'es', 'frFR', 'zhCN']);
66
});
77

88
it('should export custom-properties', () => {

src/test-utils.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable global-require */
12
import React from 'react';
23
import { render } from 'react-testing-library';
34
import { IntlProvider, addLocaleData } from 'react-intl';
@@ -6,11 +7,29 @@ import { createMemoryHistory } from 'history';
67
import en from 'react-intl/locale-data/en';
78
import de from 'react-intl/locale-data/de';
89
import es from 'react-intl/locale-data/es';
9-
import messages from '../i18n/core.json';
10+
import frFR from 'react-intl/locale-data/fr';
11+
import zhCN from 'react-intl/locale-data/zh';
1012

1113
addLocaleData(en);
1214
addLocaleData(de);
1315
addLocaleData(es);
16+
addLocaleData(frFR);
17+
addLocaleData(zhCN);
18+
19+
const getMessagesForLocale = locale => {
20+
switch (locale) {
21+
case 'de':
22+
return require('../i18n/data/de.json');
23+
case 'es':
24+
return require('../i18n/data/es.json');
25+
case 'fr-FR':
26+
return require('../i18n/data/fr-FR.json');
27+
case 'zh-CN':
28+
return require('../i18n/data/zh-CN.json');
29+
default:
30+
return require('../i18n/data/en.json');
31+
}
32+
};
1433

1534
const customRender = (
1635
node,
@@ -22,7 +41,7 @@ const customRender = (
2241
} = {}
2342
) => ({
2443
...render(
25-
<IntlProvider locale={locale} messages={messages}>
44+
<IntlProvider locale={locale} messages={getMessagesForLocale(locale)}>
2645
<Router history={history}>{node}</Router>
2746
</IntlProvider>,
2847
rtlOptions

test/percy/suite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { IntlProvider, addLocaleData } from 'react-intl';
44
import en from 'react-intl/locale-data/en';
5-
import { i18n as messages } from '../../dist/ui-kit.esm';
5+
import messages from '../../i18n/data/en.json';
66

77
addLocaleData(en);
88

99
const Suite = props => (
10-
<IntlProvider locale="en" messages={messages.en}>
10+
<IntlProvider locale="en" messages={messages}>
1111
<div>{props.children}</div>
1212
</IntlProvider>
1313
);

0 commit comments

Comments
 (0)