Skip to content

Commit 51a9223

Browse files
committed
Feature(i18n): support react-i18n withNamespace function
1 parent b448d3f commit 51a9223

File tree

31 files changed

+670
-1025
lines changed

31 files changed

+670
-1025
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3.5'
1+
version: '3.7'
22

33
services:
44
web:

frontend/src/components/Dropdown/__tests__/dropdown.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Dropdown', () => {
1111
const renderer = TestRenderer.create(
1212
<MemoryRouter>
1313
<div>
14-
<Dropdown id='id' dropdownLists={['dropdown']} t={tMock} i18n={i18nMock} />,
14+
<Dropdown id='id' dropdownLists={['dropdown']} t={tMock} tReady={true} i18n={i18nMock} />,
1515
</div>
1616
</MemoryRouter>,
1717
);

frontend/src/components/Dropdown/dropdown.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
2-
import { InjectedI18nProps, InjectedTranslateProps, translate } from 'react-i18next';
2+
import { withNamespaces, WithNamespaces as Ii18nProps } from 'react-i18next';
33
import { Link } from 'react-router-dom';
44

55
import i18ns from './i18n';
66

7-
interface IDropdownProps extends InjectedI18nProps, InjectedTranslateProps {
7+
interface IDropdownProps extends Ii18nProps {
88
id: string;
99
dropdownLists: string[];
1010
}
@@ -44,4 +44,4 @@ export class Dropdown extends React.Component<IDropdownProps> {
4444
}
4545
}
4646

47-
export default translate('Dropdown')(Dropdown);
47+
export default withNamespaces('Dropdown')(Dropdown);

frontend/src/components/Footer/__tests__/footer.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Footer } from '../footer';
77
describe('Footer', () => {
88
it('should renders correctly', () => {
99
const renderer = TestRenderer.create(
10-
<Footer t={tMock} i18n={i18nMock} />,
10+
<Footer t={tMock} tReady={true} i18n={i18nMock} />,
1111
);
1212
expect(renderer).toMatchSnapshot();
1313
renderer.unmount();

frontend/src/components/Footer/footer.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React from 'react';
2-
import { InjectedI18nProps, InjectedTranslateProps, translate } from 'react-i18next';
2+
import { withNamespaces, WithNamespaces as Ii18nProps } from 'react-i18next';
33

44
import i18ns from './i18n';
55

6-
interface IFooterProps extends InjectedI18nProps, InjectedTranslateProps { }
7-
8-
export class Footer extends React.Component<IFooterProps> {
9-
constructor(props: IFooterProps) {
6+
export class Footer extends React.Component<Ii18nProps> {
7+
constructor(props: Ii18nProps) {
108
super(props);
119
this.loadI18ns();
1210
}
@@ -50,4 +48,4 @@ export class Footer extends React.Component<IFooterProps> {
5048
}
5149
}
5250

53-
export default translate('Footer')(Footer);
51+
export default withNamespaces('Footer')(Footer);

frontend/src/components/Header/__tests__/header.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Header', () => {
1313
const renderer = TestRenderer.create(
1414
<MemoryRouter>
1515
<div>
16-
<Header pathname='/parallax' t={tMock} i18n={i18nMock} />,
16+
<Header pathname='/parallax' t={tMock} tReady={true} i18n={i18nMock} />,
1717
</div>
1818
</MemoryRouter>,
1919
);

frontend/src/components/Header/header.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { InjectedI18nProps, InjectedTranslateProps, translate } from 'react-i18next';
2+
import { withNamespaces, WithNamespaces as Ii18nProps } from 'react-i18next';
33
import { connect } from 'react-redux';
44
import { Link } from 'react-router-dom';
55

@@ -15,7 +15,7 @@ interface IHeaderStateProps {
1515
pathname: string;
1616
}
1717

18-
interface IHeaderProps extends IHeaderStateProps, InjectedI18nProps, InjectedTranslateProps { }
18+
interface IHeaderProps extends IHeaderStateProps, Ii18nProps { }
1919

2020
export class Header extends React.Component<IHeaderProps> {
2121
constructor(props: IHeaderProps) {
@@ -90,4 +90,4 @@ const mapStateToProps = (state: IGlobalState): IHeaderStateProps => ({
9090
export default connect(
9191
mapStateToProps,
9292
null,
93-
)(translate('Header')(Header));
93+
)(withNamespaces('Header')(Header));

frontend/src/pages/HomePage/__tests__/homePage.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jest.mock('../components/TranslationButton', () => 'TranslationButton');
1212
describe('HomePage', () => {
1313
it('should renders correctly', () => {
1414
const renderer = TestRenderer.create(
15-
<HomePage t={tMock} i18n={i18nMock} />,
15+
<HomePage t={tMock} tReady={true} i18n={i18nMock} />,
1616
);
1717
expect(renderer).toMatchSnapshot();
1818
renderer.unmount();

frontend/src/pages/HomePage/components/Carousel/__tests__/carousel.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Carousel } from '../carousel';
88
describe('Carousel', () => {
99
it('should renders correctly', () => {
1010
const renderer = TestRenderer.create(
11-
<Carousel t={tMock} i18n={i18nMock} />,
11+
<Carousel t={tMock} tReady={true} i18n={i18nMock} />,
1212
);
1313
expect(renderer).toMatchSnapshot();
1414
renderer.unmount();

frontend/src/pages/HomePage/components/Carousel/carousel.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { InjectedI18nProps, InjectedTranslateProps, translate } from 'react-i18next';
2+
import { withNamespaces, WithNamespaces as Ii18nProps } from 'react-i18next';
33

44
import { CAROUSEL_AUTOPLAY_INTERVAL, TOAST_DISPLAY_DURATION, TOOLTIP_DELAY_TIME } from './constants/carousel';
55
import i18ns from './i18n';
@@ -20,12 +20,10 @@ const toastConfig: Partial<M.ToastOptions> = {
2020
displayLength: TOAST_DISPLAY_DURATION,
2121
};
2222

23-
interface ICarouselProps extends InjectedI18nProps, InjectedTranslateProps { }
24-
25-
export class Carousel extends React.Component<ICarouselProps> {
23+
export class Carousel extends React.Component<Ii18nProps> {
2624
public timer: number = 0;
2725

28-
constructor(props: ICarouselProps) {
26+
constructor(props: Ii18nProps) {
2927
super(props);
3028
this.loadI18ns();
3129
}
@@ -92,4 +90,4 @@ export class Carousel extends React.Component<ICarouselProps> {
9290
}
9391
}
9492

95-
export default translate('Carousel')(Carousel);
93+
export default withNamespaces('Carousel')(Carousel);

0 commit comments

Comments
 (0)