From 43da21db6b791904ff1d1a5a24c15bfe592064e3 Mon Sep 17 00:00:00 2001 From: yashar Date: Fri, 15 Sep 2017 14:03:40 +0430 Subject: [PATCH 01/34] Disable debug mode in i18next --- src/i18n.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index ea7622042..d45f2f59b 100755 --- a/src/i18n.js +++ b/src/i18n.js @@ -17,7 +17,7 @@ i18n ns: ['common'], defaultNS: 'common', - debug: true, + debug: false, // cache: { // enabled: true, @@ -33,5 +33,4 @@ i18n }, }); - export default i18n; From f9cad7c1e7c968d8a0972a2ea8093f998116abeb Mon Sep 17 00:00:00 2001 From: yashar Date: Mon, 18 Sep 2017 14:07:52 +0430 Subject: [PATCH 02/34] Add i18n strings to account components --- src/components/account/account.js | 11 +++++++---- src/components/account/account.test.js | 3 +++ src/components/account/address.js | 2 +- src/components/account/address.test.js | 7 +++++-- src/components/account/index.js | 3 ++- src/components/account/index.test.js | 9 +++++++-- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/components/account/account.js b/src/components/account/account.js index 8b93bba86..24984024a 100644 --- a/src/components/account/account.js +++ b/src/components/account/account.js @@ -11,8 +11,9 @@ import { toRawLsk } from '../../utils/lsk'; * * @param {object} props - include properties of component */ + const Account = ({ - account, peers, + account, peers, t, }) => { const status = (peers.status && peers.status.online) ? check : @@ -21,13 +22,15 @@ const Account = ({ return (
-
+
-

Peer

+

+ {t('Peer')} +

@@ -50,7 +53,7 @@ const Account = ({
-

Balance

+

{t('Balance')}

{ beforeEach(() => { props = { + t: key => key, + i18n: {}, + store: {}, onActivePeerUpdated: sinon.spy(), peers: { status: { diff --git a/src/components/account/address.js b/src/components/account/address.js index ea8dd8ab0..c266aa5cf 100644 --- a/src/components/account/address.js +++ b/src/components/account/address.js @@ -3,7 +3,7 @@ import grid from 'flexboxgrid/dist/flexboxgrid.css'; import styles from './account.css'; const Address = (props) => { - const title = props.isDelegate ? 'Delegate' : 'Address'; + const title = props.isDelegate ? props.t('Delegate') : props.t('Address'); const content = props.isDelegate ? (

diff --git a/src/components/account/address.test.js b/src/components/account/address.test.js index bf577f452..02100e738 100644 --- a/src/components/account/address.test.js +++ b/src/components/account/address.test.js @@ -8,8 +8,9 @@ describe('Address', () => { const inputValue = { isDelegate: false, address: '16313739661670634666L', + t: key => key, }; - const expectedHeaderValue = 'Address'; + const expectedHeaderValue = 'address'; const wrapper = shallow(

); expect(wrapper.find('#firstBox').text()).to.be.equal(expectedHeaderValue); }); @@ -21,8 +22,9 @@ describe('Address', () => { delegate: { username: 'lisk-nano', }, + t: key => key, }; - const expectedHeaderValue = 'Delegate'; + const expectedHeaderValue = 'delegate'; const wrapper = shallow(
); expect(wrapper.find('#firstBox').text()).to.be.equal(expectedHeaderValue); }); @@ -34,6 +36,7 @@ describe('Address', () => { delegate: { username: 'lisk-nano', }, + t: key => key, }; const expectedValue = 'lisk-nano'; const wrapper = shallow(
); diff --git a/src/components/account/index.js b/src/components/account/index.js index 624f56a65..1f38dcfed 100644 --- a/src/components/account/index.js +++ b/src/components/account/index.js @@ -1,4 +1,5 @@ import { connect } from 'react-redux'; +import { translate } from 'react-i18next'; import Account from './account'; /** @@ -11,4 +12,4 @@ const mapStateToProps = state => ({ export default connect( mapStateToProps, -)(Account); +)(translate()(Account)); diff --git a/src/components/account/index.test.js b/src/components/account/index.test.js index 56a6b0431..e9561e84b 100644 --- a/src/components/account/index.test.js +++ b/src/components/account/index.test.js @@ -1,7 +1,9 @@ import React from 'react'; import { expect } from 'chai'; import { mount } from 'enzyme'; +import PropTypes from 'prop-types'; import AccountHOC from './index'; +import i18n from '../../i18n'; describe('Account HOC', () => { // Mocking store @@ -32,8 +34,11 @@ describe('Account HOC', () => { }), }; const options = { - context: { store }, - // childContextTypes: { store: PropTypes.object.isRequired }, + context: { i18n, store }, + childContextTypes: { + i18n: PropTypes.object.isRequired, + store: PropTypes.object.isRequired, + }, }; let props; From 5d395c53fb1cb0e4e3ff0d21cc0fe87405d5e1aa Mon Sep 17 00:00:00 2001 From: yashar Date: Mon, 18 Sep 2017 14:08:33 +0430 Subject: [PATCH 03/34] Add i18n strings to secondPassphrase component --- src/components/secondPassphrase/index.js | 3 ++- src/components/secondPassphrase/index.test.js | 8 +++++++- src/components/secondPassphrase/secondPassphrase.js | 6 +++--- src/components/secondPassphrase/secondPassphrase.test.js | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/secondPassphrase/index.js b/src/components/secondPassphrase/index.js index 978f87dd2..e879e2fa1 100644 --- a/src/components/secondPassphrase/index.js +++ b/src/components/secondPassphrase/index.js @@ -1,4 +1,5 @@ import { connect } from 'react-redux'; +import { translate } from 'react-i18next'; import { dialogDisplayed } from '../../actions/dialog'; import { secondPassphraseRegistered } from '../../actions/account'; import SecondPassphrase from './secondPassphrase'; @@ -19,4 +20,4 @@ const mapDispatchToProps = dispatch => ({ export default connect( mapStateToProps, mapDispatchToProps, -)(SecondPassphrase); +)(translate()(SecondPassphrase)); diff --git a/src/components/secondPassphrase/index.test.js b/src/components/secondPassphrase/index.test.js index 2a17bf2db..b00742b64 100644 --- a/src/components/secondPassphrase/index.test.js +++ b/src/components/secondPassphrase/index.test.js @@ -2,7 +2,9 @@ import React from 'react'; import { expect } from 'chai'; import { mount } from 'enzyme'; import { Provider } from 'react-redux'; +import { I18nextProvider } from 'react-i18next'; import configureMockStore from 'redux-mock-store'; +import i18n from '../../i18n'; import SecondPassphraseHOC from './index'; @@ -16,7 +18,11 @@ describe('SecondPassphraseHOC', () => { }); beforeEach(() => { - wrapper = mount(); + wrapper = mount( + + + + ); }); it('should render SecondPassphrase', () => { diff --git a/src/components/secondPassphrase/secondPassphrase.js b/src/components/secondPassphrase/secondPassphrase.js index 67590d497..a5cd26d8c 100644 --- a/src/components/secondPassphrase/secondPassphrase.js +++ b/src/components/secondPassphrase/secondPassphrase.js @@ -8,7 +8,7 @@ import styles from './secondPassphrase.css'; import Fees from '../../constants/fees'; const SecondPassphrase = ({ - account, peers, setActiveDialog, registerSecondPassphrase, + account, peers, setActiveDialog, registerSecondPassphrase, t, }) => { const onLoginSubmission = (secondPassphrase) => { registerSecondPassphrase({ @@ -20,10 +20,10 @@ const SecondPassphrase = ({ return ( !account.secondSignature ? - setActiveDialog({ - title: 'Register second passphrase', + title: t('Register second passphrase'), childComponent: Passphrase, childComponentProps: { onPassGenerated: onLoginSubmission, diff --git a/src/components/secondPassphrase/secondPassphrase.test.js b/src/components/secondPassphrase/secondPassphrase.test.js index f2d4722b9..24c4a8726 100644 --- a/src/components/secondPassphrase/secondPassphrase.test.js +++ b/src/components/secondPassphrase/secondPassphrase.test.js @@ -24,6 +24,7 @@ describe('SecondPassphrase', () => { peers: {}, setActiveDialog: () => {}, registerSecondPassphrase: () => {}, + t: key => key, }; describe('Account with second passphrase', () => { From 5f3acfed02458d04b2bc307366e487ae8c7b11ec Mon Sep 17 00:00:00 2001 From: yashar Date: Mon, 18 Sep 2017 14:09:39 +0430 Subject: [PATCH 04/34] Add i18n strings to tabs component --- src/components/tabs/index.js | 3 ++- src/components/tabs/tabs.js | 35 +++++++++++++++++++------------- src/components/tabs/tabs.test.js | 10 +++++---- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/components/tabs/index.js b/src/components/tabs/index.js index 38043fe14..1d69b7a1d 100644 --- a/src/components/tabs/index.js +++ b/src/components/tabs/index.js @@ -1,10 +1,11 @@ import { connect } from 'react-redux'; import { withRouter } from 'react-router'; +import { translate } from 'react-i18next'; import Tabs from './tabs'; const mapStateToProps = state => ({ isDelegate: state.account.isDelegate, }); -export default withRouter(connect(mapStateToProps)(Tabs)); +export default withRouter(connect(mapStateToProps)(translate()(Tabs))); diff --git a/src/components/tabs/tabs.js b/src/components/tabs/tabs.js index 61b3a8c3d..e21063bf6 100644 --- a/src/components/tabs/tabs.js +++ b/src/components/tabs/tabs.js @@ -8,7 +8,7 @@ const tabs = [ 'Forging', ]; -const getTabs = isDelegate => (tabs.filter(t => t !== 'Forging' || isDelegate)); +const getTabs = (isDelegate, labels) => (labels.filter((item, idx) => idx !== 2 || isDelegate)); const getIndex = history => ( tabs.map(t => t.toLowerCase()) @@ -22,18 +22,25 @@ const navigate = (history, index) => { } }; -const Tabs = props => ( - - {getTabs(props.isDelegate).map((tab, index) => - )} - -); +const Tabs = (props) => { + const tabsLabel = [ + props.t('Transactions'), + props.t('Voting'), + props.t('Forging'), + ]; + return ( + + {getTabs(props.isDelegate, tabsLabel).map((tab, index) => + )} + + ); +}; export default Tabs; diff --git a/src/components/tabs/tabs.test.js b/src/components/tabs/tabs.test.js index 868f9bd67..f39ff714e 100644 --- a/src/components/tabs/tabs.test.js +++ b/src/components/tabs/tabs.test.js @@ -14,23 +14,25 @@ describe('Tabs', () => { push: sinon.spy(), }; + const t = key => key; + it('should render react toolbox Tabs component', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(ToolboxTabs).exists()).to.equal(true); }); it('should render 3 Tab components if props.isDelegate', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(Tab)).to.have.lengthOf(3); }); it('should render 2 Tab components if !props.isDelegate', () => { - const wrapper = mount(); + const wrapper = mount(); expect(wrapper.find(Tab)).to.have.lengthOf(2); }); it('should allow to change active tab', () => { - const wrapper = mount(); + const wrapper = mount(); wrapper.find(Tab).at(0).simulate('click'); expect(history.push).to.have.been.calledWith('transactions'); }); From a932abf98c655e7b37bc6e4bc2ebc9e5be4ed3bb Mon Sep 17 00:00:00 2001 From: yashar Date: Mon, 18 Sep 2017 14:16:53 +0430 Subject: [PATCH 05/34] Add i18n strings to timestamp component --- src/components/timestamp/index.js | 17 +++++++++++------ src/components/timestamp/index.test.js | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/components/timestamp/index.js b/src/components/timestamp/index.js index b76be8a29..d91ad1895 100644 --- a/src/components/timestamp/index.js +++ b/src/components/timestamp/index.js @@ -1,8 +1,9 @@ import React from 'react'; import moment from 'moment'; import Tooltip from 'react-toolbox/lib/tooltip'; -// import omit from 'lodash/omit'; import theme from 'react-toolbox/lib/tooltip/theme.css'; +import { translate } from 'react-i18next'; +import i18n from '../../i18n'; const _fix = value => new Date((((Date.UTC(2016, 4, 24, 17, 0, 0, 0) / 1000) + value) * 1000)); /** @@ -42,12 +43,16 @@ export const TooltipWrapper = (props) => { return
; }; -export const Time = (props) => { +export const Time = translate()((props) => { + moment.locale(i18n.language); const time = moment(_fix(props.label)); return {time.fromNow(true)}; -}; +}); -export const TooltipTime = (props) => { +export const TooltipTime = translate()((props) => { + moment.locale(i18n.language); const time = moment(_fix(props.label)); - return ; -}; + return ( + + ); +}); diff --git a/src/components/timestamp/index.test.js b/src/components/timestamp/index.test.js index b9b9c3e8c..a3d72cc3f 100644 --- a/src/components/timestamp/index.test.js +++ b/src/components/timestamp/index.test.js @@ -1,7 +1,9 @@ import React from 'react'; import { expect } from 'chai'; -import { shallow, mount } from 'enzyme'; +import { mount } from 'enzyme'; import sinon from 'sinon'; +import PropTypes from 'prop-types'; +import i18n from '../../i18n'; import { Time, TooltipTime, TooltipWrapper } from './index'; sinon.useFakeTimers(new Date(2017, 1, 15).getTime()); @@ -9,7 +11,12 @@ describe('Time', () => { it('shows "5 months" for the equivalent timestamp (35929631)', () => { const inputValue = 35929631; const expectedValue = '5 months'; - const wrapper = shallow(