Skip to content

Commit

Permalink
Feature(translation): upgrade react-i18next to v10
Browse files Browse the repository at this point in the history
  • Loading branch information
Armour committed Feb 6, 2019
1 parent 8368060 commit 2c06c58
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 120 deletions.
2 changes: 1 addition & 1 deletion __mocks__/react-i18next.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const NamespacesConsumer = ({ children }: any) => children((k: string) => k, { i18n: {} });
export const Translation = ({ children }: any) => children((k: string) => k, { i18n: {} });
6 changes: 3 additions & 3 deletions frontend/src/components/Dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';
import { Link } from 'react-router-dom';

interface IDropdownProps {
Expand All @@ -19,15 +19,15 @@ export class Dropdown extends React.Component<IDropdownProps> {

public render() {
return (
<NamespacesConsumer ns='common'>
<Translation ns='common'>
{(t) => (
<ul id={this.props.id} className='dropdown-content'>
{this.props.dropdownLists.map((key) =>
<li key={key}><Link to={`/${key}`}>{t('dropdown.' + key)}</Link></li>,
)}
</ul>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Footer/footer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

export class Footer extends React.Component {
public render() {
return (
<NamespacesConsumer ns='common'>
<Translation ns='common'>
{(t) => (
<footer className='page-footer'>
<div className='container'>
Expand Down Expand Up @@ -32,7 +32,7 @@ export class Footer extends React.Component {
</div>
</footer>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Header/header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';

Expand Down Expand Up @@ -37,7 +37,7 @@ export class Header extends React.Component<IHeaderStateProps> {
public render() {
const dropdownList = ['parallax'];
return (
<NamespacesConsumer ns='common'>
<Translation ns='common'>
{(t) => (
<div>
<nav>
Expand Down Expand Up @@ -68,7 +68,7 @@ export class Header extends React.Component<IHeaderStateProps> {
</ul>
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/HomePage/components/Carousel/carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

import { CAROUSEL_AUTOPLAY_INTERVAL, TOAST_DISPLAY_DURATION, TOOLTIP_DELAY_TIME } from './constants/carousel';

Expand Down Expand Up @@ -55,7 +55,7 @@ export class Carousel extends React.Component {

public render() {
return (
<NamespacesConsumer ns='homePage'>
<Translation ns='homePage'>
{(t) => (
this.initTooltip(t('carousel.tooltipText')),
<div className='carousel carousel-slider center z-depth-3' data-indicators='true'>
Expand All @@ -82,7 +82,7 @@ export class Carousel extends React.Component {
</a>
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/HomePage/components/Pushpin/pushpin.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

const styles = require('./pushpin.scss');

Expand All @@ -11,7 +11,7 @@ interface IPushpinProps {
export class Pushpin extends React.Component<IPushpinProps> {
public render() {
return (
<NamespacesConsumer ns='homePage'>
<Translation ns='homePage'>
{(t) => (
<div id={this.props.color} className={`${styles.pushpin} ${this.props.color} ${this.props.depth}`}>
<nav className='pushpin-nav pin-top' data-target={'pushpin-' + this.props.color}>
Expand All @@ -27,7 +27,7 @@ export class Pushpin extends React.Component<IPushpinProps> {
</nav>
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import i18next from 'i18next';
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

const floatingActionButtonConfig: Partial<M.FloatingActionButtonOptions> = {
direction: 'top',
Expand All @@ -19,7 +19,7 @@ export class TranslationButton extends React.Component {

public render() {
return (
<NamespacesConsumer>
<Translation>
{(_, {i18n}) => (
<div className='fixed-action-btn vertical'>
<a className='btn-floating btn-large red'>
Expand All @@ -32,7 +32,7 @@ export class TranslationButton extends React.Component {
</ul>
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/HomePage/homePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

import Carousel from './components/Carousel';
import Pushpin from './components/Pushpin';
Expand Down Expand Up @@ -27,7 +27,7 @@ export class HomePage extends React.Component {

public render() {
return (
<NamespacesConsumer ns='homePage'>
<Translation ns='homePage'>
{(t) => (
<div>
<div className={styles['home-page-block']}>
Expand All @@ -45,7 +45,7 @@ export class HomePage extends React.Component {
<TranslationButton />
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/NotFoundPage/notFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

const styles = require('./notFoundPage.scss');

Expand Down Expand Up @@ -28,14 +28,14 @@ export class NotFoundPage extends React.Component<{}, INotFoundPageState> {

public render() {
return (
<NamespacesConsumer ns='notFoundPage'>
<Translation ns='notFoundPage'>
{(t) => (
<div>
<h1 className='page-title'>{t('title')}</h1>
<img className={styles['not-found-img']} src={require('./assets/images/' + notFoundImageList[this.state.imageId])} alt='not-found-img' height='550px' width='750px' />
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/ParallaxPage/parallaxPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

import PrismCodes, { PARALLAX_CODE } from './components/PrismCodes';

Expand All @@ -13,7 +13,7 @@ export class ParallaxPage extends React.Component {

public render() {
return (
<NamespacesConsumer ns='parallaxPage'>
<Translation ns='parallaxPage'>
{(t) => (
<div>
<div className='white'>
Expand Down Expand Up @@ -43,7 +43,7 @@ export class ParallaxPage extends React.Component {
</div>
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { List } from 'immutable';
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';
import { connect } from 'react-redux';
import { AnyAction, Dispatch } from 'redux';

Expand Down Expand Up @@ -49,7 +49,7 @@ export class FetchNote extends React.Component<IFetchNoteProps> {
</div>
);
return (
<NamespacesConsumer ns='reactPage'>
<Translation ns='reactPage'>
{(t) => (
<div className={`center-align z-depth-2 ${styles['fetch-note-layout']}`}>
<span className={styles['fetch-note-title']}>{t('fetchNote.asyncCalls')}</span>
Expand All @@ -62,7 +62,7 @@ export class FetchNote extends React.Component<IFetchNoteProps> {
{this.props.error !== '' && errorPanel}
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

import TodoFilter from './components/TodoFilter';

export class TodoFooter extends React.Component {
public render() {
return (
<NamespacesConsumer ns='reactPage'>
<Translation ns='reactPage'>
{(t) => (
<div className='todo-footer'>
<TodoFilter filter='SHOW_ALL'>
Expand All @@ -20,7 +20,7 @@ export class TodoFooter extends React.Component {
</TodoFilter>
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';
import { connect } from 'react-redux';
import { AnyAction, Dispatch } from 'redux';

Expand Down Expand Up @@ -29,7 +29,7 @@ export class TodoInput extends React.Component<ITodoInputDispatchProps> {

public render() {
return (
<NamespacesConsumer ns='reactPage'>
<Translation ns='reactPage'>
{(t) => (
<div>
<form onSubmit={this.onSubmit}>
Expand All @@ -40,7 +40,7 @@ export class TodoInput extends React.Component<ITodoInputDispatchProps> {
</form>
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

import TodoFooter from './components/TodoFooter';
import TodoInput from './components/TodoInput';
Expand All @@ -10,7 +10,7 @@ const styles = require('./todoLayout.scss');
export class TodoLayout extends React.Component {
public render() {
return (
<NamespacesConsumer ns='reactPage'>
<Translation ns='reactPage'>
{(t) => (
<div className={`center-align z-depth-2 ${styles['todo-layout']}`}>
<span className={styles['todo-title']}>{t('title')}</span>
Expand All @@ -19,7 +19,7 @@ export class TodoLayout extends React.Component {
<TodoFooter />
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/ReactPage/reactPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { NamespacesConsumer } from 'react-i18next';
import { Translation } from 'react-i18next';

import FetchNote from './components/FetchNote';
import TodoLayout from './components/TodoLayout';

export class ReactPage extends React.Component {
public render() {
return (
<NamespacesConsumer ns='reactPage'>
<Translation ns='reactPage'>
{(t) => (
<div>
<div className='react-container'>
Expand All @@ -17,7 +17,7 @@ export class ReactPage extends React.Component {
</div>
</div>
)}
</NamespacesConsumer>
</Translation>
);
}
}
Expand Down
Loading

0 comments on commit 2c06c58

Please sign in to comment.