Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #861 from LiskHQ/850-translations
Browse files Browse the repository at this point in the history
Translate every hardcoded string - Closes #850
  • Loading branch information
gina contrino authored Oct 13, 2017
2 parents e5976bc + 3b57aef commit abf6258
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/actions/account.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import i18next from 'i18next';
import actionTypes from '../constants/actions';
import { setSecondPassphrase, send } from '../utils/api/account';
import { registerDelegate } from '../utils/api/delegate';
Expand Down Expand Up @@ -62,7 +63,7 @@ export const secondPassphraseRegistered = ({ activePeer, secondPassphrase, accou
type: transactionTypes.setSecondPassphrase,
}));
}).catch((error) => {
const text = (error && error.message) ? error.message : 'An error occurred while registering your second passphrase. Please try again.';
const text = (error && error.message) ? error.message : i18next.t('An error occurred while registering your second passphrase. Please try again.');
dispatch(errorAlertDialogDisplayed({ text }));
});
dispatch(passphraseUsed(account.passphrase));
Expand All @@ -88,7 +89,7 @@ export const delegateRegistered = ({
}));
})
.catch((error) => {
const text = error && error.message ? `${error.message}.` : 'An error occurred while registering as delegate.';
const text = error && error.message ? `${error.message}.` : i18next.t('An error occurred while registering as delegate.');
const actionObj = errorAlertDialogDisplayed({ text });
dispatch(actionObj);
});
Expand All @@ -113,7 +114,7 @@ export const sent = ({ activePeer, account, recipientId, amount, passphrase, sec
}));
})
.catch((error) => {
const text = error && error.message ? `${error.message}.` : 'An error occurred while creating the transaction.';
const text = error && error.message ? `${error.message}.` : i18next.t('An error occurred while creating the transaction.');
dispatch(errorAlertDialogDisplayed({ text }));
});
dispatch(passphraseUsed(passphrase));
Expand Down
16 changes: 8 additions & 8 deletions src/components/passphraseInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PassphraseInput extends React.Component {
let error;

if (!value) {
error = 'Required';
error = this.props.t('Required');
} else if (!isValidPassphrase(value)) {
error = this.getPassphraseValidationError(value);
} else if (this.hasExtraWhitespace(value)) {
Expand All @@ -35,20 +35,20 @@ class PassphraseInput extends React.Component {
getPassphraseValidationError(passphrase) {
const mnemonic = passphrase.trim().split(' ');
if (mnemonic.length < 12) {
return `Passphrase should have 12 words, entered passphrase has ${mnemonic.length}`;
return this.props.t('Passphrase should have 12 words, entered passphrase has {{length}}', { length: mnemonic.length });
}

const invalidWord = mnemonic.find(word => !inDictionary(word.toLowerCase()));
if (invalidWord) {
if (invalidWord.length >= 2 && invalidWord.length <= 8) {
const validWord = findSimilarWord(invalidWord);
if (validWord) {
return `Word "${invalidWord}" is not on the passphrase Word List. Most similar word on the list is "${findSimilarWord(invalidWord)}"`;
return this.props.t('Word "{{invalidWord}}" is not on the passphrase Word List. Most similar word on the list is "{{similarWord}}"', { invalidWord, similarWord: findSimilarWord(invalidWord) });
}
}
return `Word "${invalidWord}" is not on the passphrase Word List.`;
return this.props.t('Word "{{invalidWord}}" is not on the passphrase Word List.', { invalidWord });
}
return 'Passphrase is not valid';
return this.props.t('Passphrase is not valid');
}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -60,11 +60,11 @@ class PassphraseInput extends React.Component {
// eslint-disable-next-line class-methods-use-this
getPassphraseWhitespaceError(passphrase) {
if (passphrase.replace(/^\s+/, '') !== passphrase) {
return 'Passphrase contains unnecessary whitespace at the beginning';
return this.props.t('Passphrase contains unnecessary whitespace at the beginning');
} else if (passphrase.replace(/\s+$/, '') !== passphrase) {
return 'Passphrase contains unnecessary whitespace at the end';
return this.props.t('Passphrase contains unnecessary whitespace at the end');
} else if (passphrase.replace(/\s+/g, ' ') !== passphrase) {
return 'Passphrase contains extra whitespace between words';
return this.props.t('Passphrase contains extra whitespace between words');
}

return null;
Expand Down
12 changes: 7 additions & 5 deletions src/components/proxyDialog/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Input, Button } from 'react-toolbox';
import React from 'react';
import { translate } from 'react-i18next';


class ProxyDialog extends React.Component {
Expand All @@ -19,7 +20,7 @@ class ProxyDialog extends React.Component {
this.setState({
[name]: {
value,
error: value === '' ? 'Required' : '',
error: value === '' ? this.props.t('Required') : '',
},
});
}
Expand All @@ -39,21 +40,22 @@ class ProxyDialog extends React.Component {
To connect to Lisk network, you need to enter a username and password for proxy
<b> {this.props.authInfo.host} </b>
</p>
<Input label='Username' required
<Input label={this.props.t('Username')} required
className='username'
onChange={this.handleChange.bind(this, 'username')}
error={this.state.username.error}
value={this.state.username.value}/>
<Input label='Password' required type='password'
<Input label={this.props.t('Password')} required type='password'
className='password'
onChange={this.handleChange.bind(this, 'password')}
error={this.state.password.error}
value={this.state.password.value}/>
<Button primary raised
style={{ float: 'right' }}
disabled = {this.state.password.value === '' || this.state.username.value === ''}
label='Submit' type='submit' />
label={this.props.t('Submit')} type='submit' />
</form>);
}
}
export default ProxyDialog;
export default translate()(ProxyDialog);

3 changes: 2 additions & 1 deletion src/components/proxyDialog/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import { spy, mock } from 'sinon';

import i18n from '../../i18n';
import ProxyDialog from './';

describe('ProxyDialog', () => {
Expand All @@ -14,6 +14,7 @@ describe('ProxyDialog', () => {
callback: spy(),
closeDialog: spy(),
authInfo: { host: 'someProxy.com' },
i18n,
};
wrapper = mount(<ProxyDialog {...props} />);
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/verifyMessage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class VerifyMessage extends React.Component {
onChange={this.handleChange.bind(this, 'signature')} />
</section>
{this.state.result ?
<SignVerifyResult result={this.state.result} title='Original Message' /> :
<SignVerifyResult result={this.state.result} title={this.props.t('Original Message')} /> :
null
}
</div>
Expand Down
19 changes: 19 additions & 0 deletions src/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{
" Make sure that you are using the latest version of Lisk Nano.": " Make sure that you are using the latest version of Lisk Nano.",
"Account saved": "Account saved",
"Account was successfully forgotten.": "Account was successfully forgotten.",
"Add vote to": "Add vote to",
"Address": "Address",
"Address copied to clipboard": "Address copied to clipboard",
"Amount": "Amount",
"An error occurred while creating the transaction.": "An error occurred while creating the transaction.",
"An error occurred while registering as delegate.": "An error occurred while registering as delegate.",
"An error occurred while registering your second passphrase. Please try again.": "An error occurred while registering your second passphrase. Please try again.",
"Approval": "Approval",
"Back": "Back",
"Balance": "Balance",
Expand Down Expand Up @@ -61,13 +66,21 @@
"Note: After registration completes,": "Note: After registration completes,",
"Note: Digital Signatures and signed messages are not encrypted!": "Note: Digital Signatures and signed messages are not encrypted!",
"Ok": "Ok",
"Original Message": "Original Message",
"Passphrase": "Passphrase",
"Passphrase contains extra whitespace between words": "Passphrase contains extra whitespace between words",
"Passphrase contains unnecessary whitespace at the beginning": "Passphrase contains unnecessary whitespace at the beginning",
"Passphrase contains unnecessary whitespace at the end": "Passphrase contains unnecessary whitespace at the end",
"Passphrase is not valid": "Passphrase is not valid",
"Passphrase of the account is saved till the end of the session.": "Passphrase of the account is saved till the end of the session.",
"Passphrase of the account will be required to perform any transaction.": "Passphrase of the account will be required to perform any transaction.",
"Passphrase should have 12 words, entered passphrase has {{length}}": "Passphrase should have 12 words, entered passphrase has {{length}}",
"Password": "Password",
"Peer": "Peer",
"Please click Next, then move around your mouse randomly to generate a random passphrase.": "Please click Next, then move around your mouse randomly to generate a random passphrase.",
"Please keep it safe!": "Please keep it safe!",
"Press #{key} to copy": "Press #{key} to copy",
"Proxy Authentication": "Proxy Authentication",
"Public Key": "Public Key",
"Rank": "Rank",
"Receive LSK": "Receive LSK",
Expand Down Expand Up @@ -102,8 +115,10 @@
"Sign message": "Sign message",
"Signature": "Signature",
"Signing a message with this tool indicates ownership of a privateKey (secret) and provides a level of proof that you are the owner of the key. Its important to bear in mind that this is not a 100% proof as computer systems can be compromised, but is still an effective tool for proving ownership of a particular publicKey/address pair.": "Signing a message with this tool indicates ownership of a privateKey (secret) and provides a level of proof that you are the owner of the key. Its important to bear in mind that this is not a 100% proof as computer systems can be compromised, but is still an effective tool for proving ownership of a particular publicKey/address pair.",
"Submit": "Submit",
"Success": "Success",
"Testnet": "Testnet",
"The URL was invalid": "The URL was invalid",
"There are no transactions, yet.": "There are no transactions, yet.",
"This account is protected by a second passphrase": "This account is protected by a second passphrase",
"This passphrase is not recoverable and if you lose it, you will lose access to your account forever.": "This passphrase is not recoverable and if you lose it, you will lose access to your account forever.",
Expand All @@ -116,14 +131,18 @@
"Transaction Amount": "Transaction Amount",
"Transaction ID": "Transaction ID",
"Transactions": "Transactions",
"URL is invalid": "URL is invalid",
"Unable to connect to the node": "Unable to connect to the node",
"Uptime": "Uptime",
"Upvotes:": "Upvotes:",
"Username": "Username",
"Verify message": "Verify message",
"Vote": "Vote",
"Vote for delegates": "Vote for delegates",
"Voting": "Voting",
"When you have the signature, you only need the publicKey of the signer in order to verify that the message came from the right private/publicKey pair. Be aware, everybody knowing the signature and the publicKey can verify the message. If ever there is a dispute, everybody can take the publicKey and signature to a judge and prove that the message is coming from the specific private/publicKey pair.": "When you have the signature, you only need the publicKey of the signer in order to verify that the message came from the right private/publicKey pair. Be aware, everybody knowing the signature and the publicKey can verify the message. If ever there is a dispute, everybody can take the publicKey and signature to a judge and prove that the message is coming from the specific private/publicKey pair.",
"Word \"{{invalidWord}}\" is not on the passphrase Word List.": "Word \"{{invalidWord}}\" is not on the passphrase Word List.",
"Word \"{{invalidWord}}\" is not on the passphrase Word List. Most similar word on the list is \"{{similarWord}}\"": "Word \"{{invalidWord}}\" is not on the passphrase Word List. Most similar word on the list is \"{{similarWord}}\"",
"Yes! It's safe": "Yes! It's safe",
"You can select up to {{count}} delegates in one voting turn.": "You can select up to {{count}} delegates in one voting turn.",
"You can select up to {{count}} delegates in one voting turn._plural": "",
Expand Down
5 changes: 3 additions & 2 deletions src/store/middlewares/savedAccounts.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import i18next from 'i18next';
import actionTypes from '../../constants/actions';
import { successToastDisplayed } from '../../actions/toaster';

const savedAccountsMiddleware = store => next => (action) => {
next(action);
switch (action.type) {
case actionTypes.accountSaved:
store.dispatch(successToastDisplayed({ label: 'Account saved' }));
store.dispatch(successToastDisplayed({ label: i18next.t('Account saved') }));
break;
case actionTypes.accountRemoved:
store.dispatch(successToastDisplayed({ label: 'Account was successfully forgotten.' }));
store.dispatch(successToastDisplayed({ label: i18next.t('Account was successfully forgotten.') }));
break;
default:
break;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/externalLinks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import i18next from 'i18next';
import history from '../history';
import routesReg from './routes';
import { errorToastDisplayed } from '../actions/toaster';
Expand All @@ -14,7 +15,7 @@ export default {
if (route !== undefined) {
history.push(normalizedUrl);
} else {
store.dispatch(errorToastDisplayed({ label: 'The URL was invalid' }));
store.dispatch(errorToastDisplayed({ label: i18next.t('The URL was invalid') }));
}
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/login.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import i18next from 'i18next';

const validateUrl = (value) => {
const addHttp = (url) => {
const reg = /^(?:f|ht)tps?:\/\//i;
return reg.test(url) ? url : `http://${url}`;
};

const errorMessage = 'URL is invalid';
const errorMessage = i18next.t('URL is invalid');

const isValidLocalhost = url => url.hostname === 'localhost' && url.port.length > 1;
const isValidRemote = url => /(([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3})/.test(url.hostname);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/proxyLogin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import i18next from 'i18next';
import { dialogDisplayed } from '../actions/dialog';
import ProxyDialog from '../components/proxyDialog';
import store from '../store';
Expand All @@ -9,7 +10,7 @@ export default {
if (ipc) {
ipc.on('proxyLogin', (action, authInfo) => {
store.dispatch(dialogDisplayed({
title: 'Proxy Authentication',
title: i18next.t('Proxy Authentication'),
childComponent: ProxyDialog,
childComponentProps: {
authInfo,
Expand Down

0 comments on commit abf6258

Please sign in to comment.