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

Commit

Permalink
set up localisation
Browse files Browse the repository at this point in the history
  • Loading branch information
neilbryson committed Dec 16, 2018
1 parent a2c4e7c commit a1a32f8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
11 changes: 8 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React from 'react';
import { Provider } from 'react-redux';
import styled from 'styled-components';
import { LocaleProvider } from 'react-locale-hoc';

import configureStore from './configureStore';

import RootView from './views/RootView';

import locales from './helpers/locales';

const { store } = configureStore({});

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

const App = () => (
<Provider store={store}>
<Container>
<RootView />
</Container>
<LocaleProvider strings={locales}>
<Container>
<RootView />
</Container>
</LocaleProvider>
</Provider>
);

Expand Down
3 changes: 1 addition & 2 deletions src/components/Button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import clickable from 'react-clickable-hoc';

const propTypes = {
label: PropTypes.string.isRequired,
Expand Down Expand Up @@ -32,4 +31,4 @@ const Button = ({ label, ...other }) => <Container {...other}>{label}</Container
Button.propTypes = propTypes;
Button.defaultProps = defaultProps;

export default clickable(Button);
export default Button;
17 changes: 11 additions & 6 deletions src/layouts/InitialHome.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { PureComponent } from 'react';
import styled from 'styled-components';
import { connect } from 'react-redux';
import { localise } from 'react-locale-hoc';

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

Expand All @@ -18,17 +19,21 @@ class InitialHome extends PureComponent {
};

render() {
const { t } = this.props;

return (
<>
<Header>It works !</Header>
<div>Now, try clicking the button below</div>
<Header>{t('it_works')}</Header>
<div>{t('instructions')}</div>
<Button label="Click me" onClick={this.onClick} />
</>
);
}
}

export default connect(
state => ({}),
{ navigateTo }
)(InitialHome);
export default localise(
connect(
state => ({}),
{ navigateTo }
)(InitialHome)
);
21 changes: 13 additions & 8 deletions src/views/HomeView.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { localise } from 'react-locale-hoc';

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

class HomeView extends PureComponent {
render() {
if (this.props.kind === 'pop') {
return <div>You just pressed the Back button.</div>;
const { kind, t } = this.props;

if (kind === 'pop') {
return <div>{t('message')}</div>;
}

return <InitialHome />;
}
}

export default connect(
state => ({
kind: state.location.kind,
}),
{}
)(HomeView);
export default localise(
connect(
state => ({
kind: state.location.kind,
}),
{}
)(HomeView)
);
8 changes: 6 additions & 2 deletions src/views/NextView.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react';

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

export default NextView;
const NextView = ({ t }) => {
return <div>{t('next_instructions')}</div>;
};

export default localise(NextView);

0 comments on commit a1a32f8

Please sign in to comment.