mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fallback to English and then the key for I18nProvider#t
This commit is contained in:
parent
2526f8a1d8
commit
94489b544a
@ -8,8 +8,11 @@ const t = require('../i18n-helper').getMessage
|
||||
class I18nProvider extends Component {
|
||||
getChildContext () {
|
||||
const { localeMessages } = this.props
|
||||
const { current, en } = localeMessages
|
||||
return {
|
||||
t: t.bind(null, localeMessages),
|
||||
t (key, ...args) {
|
||||
return t(current, key, ...args) || t(en, key, ...args) || `[${key}]`
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,22 @@
|
||||
// cross-browser connection to extension i18n API
|
||||
const log = require('loglevel')
|
||||
|
||||
/**
|
||||
* Returns a localized message for the given key
|
||||
* @param {object} locale The locale
|
||||
* @param {string} key The message key
|
||||
* @param {string[]} substitutions A list of message substitution replacements
|
||||
* @return {null|string} The localized message
|
||||
*/
|
||||
const getMessage = (locale, key, substitutions) => {
|
||||
// check locale is loaded
|
||||
if (!locale) {
|
||||
// throw new Error('Translator - has not loaded a locale yet.')
|
||||
return ''
|
||||
return null
|
||||
}
|
||||
// check entry is present
|
||||
const { current, en } = locale
|
||||
const entry = current[key] || en[key]
|
||||
if (!entry) {
|
||||
// throw new Error(`Translator - Unable to find value for "${key}"`)
|
||||
log.error(`Translator - Unable to find value for "${key}"`)
|
||||
return `[${key}]`
|
||||
if (!locale[key]) {
|
||||
log.error(`Translator - Unable to find value for key "${key}"`)
|
||||
return null
|
||||
}
|
||||
const entry = locale[key]
|
||||
let phrase = entry.message
|
||||
// perform substitutions
|
||||
if (substitutions && substitutions.length) {
|
||||
|
Loading…
Reference in New Issue
Block a user