2014-06-30 01:16:50 +00:00
|
|
|
define(["util/dom2"], function() {
|
|
|
|
|
2014-07-07 16:10:37 +00:00
|
|
|
var translationCache = {};
|
|
|
|
|
2014-06-30 01:16:50 +00:00
|
|
|
return {
|
|
|
|
//process a chunk of template HTML for i18n strings
|
|
|
|
process: function(html) {
|
|
|
|
return html.replace(/__MSG_(\w+)__/g, function(match, tag) {
|
|
|
|
return chrome.i18n.getMessage(tag);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//process the page for inline strings, marked with .i18n
|
|
|
|
page: function() {
|
|
|
|
document.findAll(".i18n").forEach(function(element) {
|
|
|
|
var original = element.innerHTML;
|
|
|
|
var translated = chrome.i18n.getMessage(original);
|
|
|
|
if (translated) element.innerHTML = translated;
|
|
|
|
});
|
2014-07-05 21:04:33 +00:00
|
|
|
},
|
|
|
|
//get a message, or return the untranslated text
|
2014-07-07 16:10:37 +00:00
|
|
|
//caches results for speed
|
2014-07-05 21:04:33 +00:00
|
|
|
get: function(message) {
|
2014-07-07 16:10:37 +00:00
|
|
|
var translated;
|
|
|
|
if (translationCache[message]) {
|
|
|
|
translated = translationCache[message];
|
|
|
|
} else {
|
|
|
|
translated = chrome.i18n.getMessage(message) || message;
|
|
|
|
translationCache[message] = translated;
|
|
|
|
}
|
|
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
|
|
translated = translated.replace(new RegExp("\$" + i, "g"), arguments[i]);
|
|
|
|
}
|
|
|
|
return translated;
|
2014-06-30 01:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|