aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-07-10 04:07:06 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-07-12 03:20:37 +0800
commit94489b544ad4a68ddd961f8b549aaac8507266e6 (patch)
tree7dc7ca549c9955e42be4a1d6841430854f42f67b /ui
parent2526f8a1d8f59758b7bc04bb088fab6ad74b16a1 (diff)
downloadtangerine-wallet-browser-94489b544ad4a68ddd961f8b549aaac8507266e6.tar
tangerine-wallet-browser-94489b544ad4a68ddd961f8b549aaac8507266e6.tar.gz
tangerine-wallet-browser-94489b544ad4a68ddd961f8b549aaac8507266e6.tar.bz2
tangerine-wallet-browser-94489b544ad4a68ddd961f8b549aaac8507266e6.tar.lz
tangerine-wallet-browser-94489b544ad4a68ddd961f8b549aaac8507266e6.tar.xz
tangerine-wallet-browser-94489b544ad4a68ddd961f8b549aaac8507266e6.tar.zst
tangerine-wallet-browser-94489b544ad4a68ddd961f8b549aaac8507266e6.zip
Fallback to English and then the key for I18nProvider#t
Diffstat (limited to 'ui')
-rw-r--r--ui/app/i18n-provider.js5
-rw-r--r--ui/i18n-helper.js22
2 files changed, 16 insertions, 11 deletions
diff --git a/ui/app/i18n-provider.js b/ui/app/i18n-provider.js
index 2856e0ed6..d46911f7c 100644
--- a/ui/app/i18n-provider.js
+++ b/ui/app/i18n-provider.js
@@ -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}]`
+ },
}
}
diff --git a/ui/i18n-helper.js b/ui/i18n-helper.js
index 269f6e1a4..bc927ee65 100644
--- a/ui/i18n-helper.js
+++ b/ui/i18n-helper.js
@@ -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) {