1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 12:56:01 +01:00
metamask-extension/ui/i18n.js

34 lines
897 B
JavaScript
Raw Normal View History

// cross-browser connection to extension i18n API
2018-01-28 06:20:56 +01:00
const chrome = chrome || null
const browser = browser || null
const extension = require('extensionizer')
2018-03-12 19:40:03 +01:00
var log = require('loglevel')
window.log = log
let getMessage
if (extension.i18n && extension.i18n.getMessage) {
getMessage = extension.i18n.getMessage
} else {
// fallback function
log.warn('browser.i18n API not available, calling back to english.')
2018-01-29 21:29:01 +01:00
const msg = require('../app/_locales/en/messages.json')
getMessage = function (key, substitutions) {
if (!msg[key]) {
log.error(key)
2018-01-29 21:29:01 +01:00
throw new Error(key)
}
let phrase = msg[key].message
if (substitutions && substitutions.length) {
phrase = phrase.replace(/\$1/g, substitutions[0])
if (substitutions.length > 1) {
phrase = phrase.replace(/\$2/g, substitutions[1])
}
}
return phrase
2018-01-28 06:20:56 +01:00
}
}
2018-01-28 06:20:56 +01:00
module.exports = getMessage