1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Add tOrKey function to I18nProvider

This commit is contained in:
Alexander Tseung 2018-07-31 19:21:25 -07:00
parent 176fb89771
commit 01f00a9ca6

View File

@ -6,6 +6,11 @@ const { compose } = require('recompose')
const t = require('../i18n-helper').getMessage const t = require('../i18n-helper').getMessage
class I18nProvider extends Component { class I18nProvider extends Component {
tOrDefault = (key, defaultValue, ...args) => {
const { localeMessages: { current, en } = {} } = this.props
return t(current, key, ...args) || t(en, key, ...args) || defaultValue
}
getChildContext () { getChildContext () {
const { localeMessages } = this.props const { localeMessages } = this.props
const { current, en } = localeMessages const { current, en } = localeMessages
@ -13,8 +18,9 @@ class I18nProvider extends Component {
t (key, ...args) { t (key, ...args) {
return t(current, key, ...args) || t(en, key, ...args) || `[${key}]` return t(current, key, ...args) || t(en, key, ...args) || `[${key}]`
}, },
tOrDefault (key, ...args) { tOrDefault: this.tOrDefault,
return t(current, key, ...args) || t(en, key, ...args) || key tOrKey (key, ...args) {
return this.tOrDefault(key, key, ...args)
}, },
} }
} }
@ -32,6 +38,7 @@ I18nProvider.propTypes = {
I18nProvider.childContextTypes = { I18nProvider.childContextTypes = {
t: PropTypes.func, t: PropTypes.func,
tOrDefault: PropTypes.func, tOrDefault: PropTypes.func,
tOrKey: PropTypes.func,
} }
const mapStateToProps = state => { const mapStateToProps = state => {