aboutsummaryrefslogtreecommitdiffstats
path: root/ui/i18n-helper.js
diff options
context:
space:
mode:
authorbrunobar79 <brunobar79@gmail.com>2018-07-14 08:53:22 +0800
committerbrunobar79 <brunobar79@gmail.com>2018-07-14 08:53:22 +0800
commitd21d408d6429e645fda8b9dfcddbe22b7a44f8ca (patch)
tree53c268ebf360d7740e0be9cd04bee3e811792a96 /ui/i18n-helper.js
parent30258328587a8942c21fce609b7949d093cd594f (diff)
parent2f4698c130331db20a27576cb1c521c8ca5106e3 (diff)
downloadtangerine-wallet-browser-d21d408d6429e645fda8b9dfcddbe22b7a44f8ca.tar.gz
tangerine-wallet-browser-d21d408d6429e645fda8b9dfcddbe22b7a44f8ca.tar.zst
tangerine-wallet-browser-d21d408d6429e645fda8b9dfcddbe22b7a44f8ca.zip
Merge branch 'develop' of github.com:MetaMask/metamask-extension into initial-trezor-support
Diffstat (limited to 'ui/i18n-helper.js')
-rw-r--r--ui/i18n-helper.js25
1 files changed, 13 insertions, 12 deletions
diff --git a/ui/i18n-helper.js b/ui/i18n-helper.js
index 79aa93116..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) {
@@ -29,8 +31,7 @@ const getMessage = (locale, key, substitutions) => {
async function fetchLocale (localeName) {
try {
const response = await fetch(`./_locales/${localeName}/messages.json`)
- const locale = await response.json()
- return locale
+ return await response.json()
} catch (error) {
log.error(`failed to fetch ${localeName} locale because of ${error}`)
return {}