Skip to content

Commit

Permalink
i18n redux solution doesn't require importing t() and passing state t…
Browse files Browse the repository at this point in the history
…o each t() call; t is just available on props.
  • Loading branch information
danjm committed Mar 22, 2018
1 parent 29cc2f8 commit d24a059
Show file tree
Hide file tree
Showing 68 changed files with 636 additions and 445 deletions.
2 changes: 1 addition & 1 deletion app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"done": {
"message": "Done"
},
"downloadStatelogs": {
"downloadStateLogs": {
"message": "Download State Logs"
},
"dropped": {
Expand Down
2 changes: 1 addition & 1 deletion app/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@
"stateLogs": {
"message": "Logs de estado"
},
"downloadStatelogs": {
"downloadStateLogs": {
"message": "Descargar logs de estados"
},
"revealSeedWords": {
Expand Down
2 changes: 1 addition & 1 deletion app/_locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"done": {
"message": "Finito"
},
"downloadStatelogs": {
"downloadStateLogs": {
"message": "Scarica i log di Stato"
},
"edit": {
Expand Down
2 changes: 1 addition & 1 deletion app/_locales/pt/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"done": {
"message": "Finalizado"
},
"downloadStatelogs": {
"downloadStateLogs": {
"message": "Descarregar Registos de Estado"
},
"edit": {
Expand Down
15 changes: 7 additions & 8 deletions ui/app/accounts/import/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('../../metamask-connect')
const t = require('../../../i18n-helper').getMessage
import Select from 'react-select'

// Subviews
Expand All @@ -15,8 +14,8 @@ module.exports = connect(mapStateToProps)(AccountImportSubview)
function mapStateToProps (state) {
return {
menuItems: [
t(this.props.localeMessages, 'privateKey'),
t(this.props.localeMessages, 'jsonFile'),
this.props.t('privateKey'),
this.props.t('jsonFile'),
],
}
}
Expand All @@ -36,7 +35,7 @@ AccountImportSubview.prototype.render = function () {
h('div.new-account-import-form', [

h('.new-account-import-disclaimer', [
h('span', t('importAccountMsg')),
h('span', this.props.t('importAccountMsg')),
h('span', {
style: {
cursor: 'pointer',
Expand All @@ -47,12 +46,12 @@ AccountImportSubview.prototype.render = function () {
url: 'https://metamask.helpscoutdocs.com/article/17-what-are-loose-accounts',
})
},
}, t('here')),
}, this.props.t('here')),
]),

h('div.new-account-import-form__select-section', [

h('div.new-account-import-form__select-label', t('selectType')),
h('div.new-account-import-form__select-label', this.props.t('selectType')),

h(Select, {
className: 'new-account-import-form__select',
Expand Down Expand Up @@ -85,9 +84,9 @@ AccountImportSubview.prototype.renderImportView = function () {
const current = type || menuItems[0]

switch (current) {
case t(this.props.localeMessages, 'privateKey'):
case this.props.t('privateKey'):
return h(PrivateKeyImportView)
case t(this.props.localeMessages, 'jsonFile'):
case this.props.t('jsonFile'):
return h(JsonImportView)
default:
return h(JsonImportView)
Expand Down
17 changes: 8 additions & 9 deletions ui/app/accounts/import/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const h = require('react-hyperscript')
const connect = require('../../metamask-connect')
const actions = require('../../actions')
const FileInput = require('react-simple-file-input').default
const t = require('../../../i18n-helper').getMessage


const HELP_LINK = 'https://support.metamask.io/kb/article/7-importing-accounts'
Expand All @@ -25,11 +24,11 @@ class JsonImportSubview extends Component {
return (
h('div.new-account-import-form__json', [

h('p', t(this.props.localeMessages, 'usedByClients')),
h('p', this.props.t('usedByClients')),
h('a.warning', {
href: HELP_LINK,
target: '_blank',
}, t(this.props.localeMessages, 'fileImportFail')),
}, this.props.t('fileImportFail')),

h(FileInput, {
readAs: 'text',
Expand All @@ -44,7 +43,7 @@ class JsonImportSubview extends Component {

h('input.new-account-import-form__input-password', {
type: 'password',
placeholder: t(this.props.localeMessages, 'enterPassword'),
placeholder: this.props.t('enterPassword'),
id: 'json-password-box',
onKeyPress: this.createKeyringOnEnter.bind(this),
}),
Expand All @@ -54,13 +53,13 @@ class JsonImportSubview extends Component {
h('button.new-account-create-form__button-cancel', {
onClick: () => this.props.goHome(),
}, [
t(this.props.localeMessages, 'cancel'),
this.props.t('cancel'),
]),

h('button.new-account-create-form__button-create', {
onClick: () => this.createNewKeychain(),
}, [
t(this.props.localeMessages, 'import'),
this.props.t('import'),
]),

]),
Expand All @@ -85,22 +84,22 @@ class JsonImportSubview extends Component {
const state = this.state

if (!state) {
const message = t('validFileImport')
const message = this.props.t('validFileImport')
return this.props.displayWarning(message)
}

const { fileContents } = state

if (!fileContents) {
const message = t(this.props.localeMessages, 'needImportFile')
const message = this.props.t('needImportFile')
return this.props.displayWarning(message)
}

const passwordInput = document.getElementById('json-password-box')
const password = passwordInput.value

if (!password) {
const message = t(this.props.localeMessages, 'needImportPassword')
const message = this.props.t('needImportPassword')
return this.props.displayWarning(message)
}

Expand Down
7 changes: 3 additions & 4 deletions ui/app/accounts/import/private-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('../../metamask-connect')
const actions = require('../../actions')
const t = require('../../../i18n-helper').getMessage

module.exports = connect(mapStateToProps, mapDispatchToProps)(PrivateKeyImportView)

Expand Down Expand Up @@ -34,7 +33,7 @@ PrivateKeyImportView.prototype.render = function () {
return (
h('div.new-account-import-form__private-key', [

h('span.new-account-create-form__instruction', t(this.props.localeMessages, 'pastePrivateKey')),
h('span.new-account-create-form__instruction', this.props.t('pastePrivateKey')),

h('div.new-account-import-form__private-key-password-container', [

Expand All @@ -51,13 +50,13 @@ PrivateKeyImportView.prototype.render = function () {
h('button.new-account-create-form__button-cancel.allcaps', {
onClick: () => goHome(),
}, [
t(this.props.localeMessages, 'cancel'),
this.props.t('cancel'),
]),

h('button.new-account-create-form__button-create.allcaps', {
onClick: () => this.createNewKeychain(),
}, [
t(this.props.localeMessages, 'import'),
this.props.t('import'),
]),

]),
Expand Down
5 changes: 2 additions & 3 deletions ui/app/accounts/import/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const inherits = require('util').inherits
const Component = require('react').Component
const h = require('react-hyperscript')
const connect = require('../../metamask-connect')
const t = require('../../../i18n-helper').getMessage

module.exports = connect(mapStateToProps)(SeedImportSubview)

Expand All @@ -21,10 +20,10 @@ SeedImportSubview.prototype.render = function () {
style: {
},
}, [
t(this.props.localeMessages, 'pasteSeed'),
this.props.t('pasteSeed'),
h('textarea'),
h('br'),
h('button', t(this.props.localeMessages, 'submit')),
h('button', this.props.t('submit')),
])
)
}
9 changes: 4 additions & 5 deletions ui/app/accounts/new-account/create-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const PropTypes = require('prop-types')
const h = require('react-hyperscript')
const connect = require('../../metamask-connect')
const actions = require('../../actions')
const t = require('../../../i18n-helper').getMessage

class NewAccountCreateForm extends Component {
constructor (props) {
Expand All @@ -14,7 +13,7 @@ class NewAccountCreateForm extends Component {

this.state = {
newAccountName: '',
defaultAccountName: t(this.props.localeMessages, 'newAccountNumberName', [newAccountNumber]),
defaultAccountName: this.props.t('newAccountNumberName', [newAccountNumber]),
}
}

Expand All @@ -25,7 +24,7 @@ class NewAccountCreateForm extends Component {
return h('div.new-account-create-form', [

h('div.new-account-create-form__input-label', {}, [
t(this.props.localeMessages, 'accountName'),
this.props.t('accountName'),
]),

h('div.new-account-create-form__input-wrapper', {}, [
Expand All @@ -41,13 +40,13 @@ class NewAccountCreateForm extends Component {
h('button.new-account-create-form__button-cancel.allcaps', {
onClick: () => this.props.goHome(),
}, [
t(this.props.localeMessages, 'cancel'),
this.props.t('cancel'),
]),

h('button.new-account-create-form__button-create.allcaps', {
onClick: () => this.props.createAccount(newAccountName || defaultAccountName),
}, [
t(this.props.localeMessages, 'create'),
this.props.t('create'),
]),

]),
Expand Down
7 changes: 3 additions & 4 deletions ui/app/accounts/new-account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const h = require('react-hyperscript')
const inherits = require('util').inherits
const connect = require('../../metamask-connect')
const actions = require('../../actions')
const t = require('../../../i18n-helper').getMessage
const { getCurrentViewContext } = require('../../selectors')
const classnames = require('classnames')

Expand Down Expand Up @@ -46,7 +45,7 @@ AccountDetailsModal.prototype.render = function () {

h('div.new-account__header', [

h('div.new-account__title', t(this.props.localeMessages, 'newAccount')),
h('div.new-account__title', this.props.t('newAccount')),

h('div.new-account__tabs', [

Expand All @@ -56,15 +55,15 @@ AccountDetailsModal.prototype.render = function () {
'new-account__tabs__unselected cursor-pointer': displayedForm !== 'CREATE',
}),
onClick: () => displayForm('CREATE'),
}, t(this.props.localeMessages, 'createDen')),
}, this.props.t('createDen')),

h('div.new-account__tabs__tab', {
className: classnames('new-account__tabs__tab', {
'new-account__tabs__selected': displayedForm === 'IMPORT',
'new-account__tabs__unselected cursor-pointer': displayedForm !== 'IMPORT',
}),
onClick: () => displayForm('IMPORT'),
}, t(this.props.localeMessages, 'import')),
}, this.props.t('import')),

]),

Expand Down
Loading

0 comments on commit d24a059

Please sign in to comment.