Skip to content
This repository was archived by the owner on May 3, 2021. It is now read-only.

Commit a1a32f8

Browse files
committed
set up localisation
1 parent a2c4e7c commit a1a32f8

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

src/App.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import React from 'react';
22
import { Provider } from 'react-redux';
33
import styled from 'styled-components';
4+
import { LocaleProvider } from 'react-locale-hoc';
45

56
import configureStore from './configureStore';
67

78
import RootView from './views/RootView';
89

10+
import locales from './helpers/locales';
11+
912
const { store } = configureStore({});
1013

1114
const Container = styled('div')`
@@ -16,9 +19,11 @@ const Container = styled('div')`
1619

1720
const App = () => (
1821
<Provider store={store}>
19-
<Container>
20-
<RootView />
21-
</Container>
22+
<LocaleProvider strings={locales}>
23+
<Container>
24+
<RootView />
25+
</Container>
26+
</LocaleProvider>
2227
</Provider>
2328
);
2429

src/components/Button.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import styled from 'styled-components';
33
import PropTypes from 'prop-types';
4-
import clickable from 'react-clickable-hoc';
54

65
const propTypes = {
76
label: PropTypes.string.isRequired,
@@ -32,4 +31,4 @@ const Button = ({ label, ...other }) => <Container {...other}>{label}</Container
3231
Button.propTypes = propTypes;
3332
Button.defaultProps = defaultProps;
3433

35-
export default clickable(Button);
34+
export default Button;

src/layouts/InitialHome.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { PureComponent } from 'react';
22
import styled from 'styled-components';
33
import { connect } from 'react-redux';
4+
import { localise } from 'react-locale-hoc';
45

56
import Button from '../components/Button';
67

@@ -18,17 +19,21 @@ class InitialHome extends PureComponent {
1819
};
1920

2021
render() {
22+
const { t } = this.props;
23+
2124
return (
2225
<>
23-
<Header>It works !</Header>
24-
<div>Now, try clicking the button below</div>
26+
<Header>{t('it_works')}</Header>
27+
<div>{t('instructions')}</div>
2528
<Button label="Click me" onClick={this.onClick} />
2629
</>
2730
);
2831
}
2932
}
3033

31-
export default connect(
32-
state => ({}),
33-
{ navigateTo }
34-
)(InitialHome);
34+
export default localise(
35+
connect(
36+
state => ({}),
37+
{ navigateTo }
38+
)(InitialHome)
39+
);

src/views/HomeView.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
import React, { PureComponent } from 'react';
22
import { connect } from 'react-redux';
3+
import { localise } from 'react-locale-hoc';
34

45
import InitialHome from '../layouts/InitialHome';
56

67
class HomeView extends PureComponent {
78
render() {
8-
if (this.props.kind === 'pop') {
9-
return <div>You just pressed the Back button.</div>;
9+
const { kind, t } = this.props;
10+
11+
if (kind === 'pop') {
12+
return <div>{t('message')}</div>;
1013
}
1114

1215
return <InitialHome />;
1316
}
1417
}
1518

16-
export default connect(
17-
state => ({
18-
kind: state.location.kind,
19-
}),
20-
{}
21-
)(HomeView);
19+
export default localise(
20+
connect(
21+
state => ({
22+
kind: state.location.kind,
23+
}),
24+
{}
25+
)(HomeView)
26+
);

src/views/NextView.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import React from 'react';
22

3-
const NextView = () => <div>Now, try pressing the Back button of the browser.</div>;
3+
import { localise } from 'react-locale-hoc';
44

5-
export default NextView;
5+
const NextView = ({ t }) => {
6+
return <div>{t('next_instructions')}</div>;
7+
};
8+
9+
export default localise(NextView);

0 commit comments

Comments
 (0)