diff --git a/_locales/en/messages.json b/_locales/en/messages.json
index 24d3985e..bf57d82a 100644
--- a/_locales/en/messages.json
+++ b/_locales/en/messages.json
@@ -205,6 +205,14 @@
"message": "Show number of styles active for the current site on the toolbar button",
"description": "Label for the checkbox controlling toolbar badge text."
},
+ "search": {
+ "message": "Search",
+ "description": "Label before the search input field in the editor shown on Ctrl-F"
+ },
+ "searchRegexp": {
+ "message": "Use /re/ syntax for regexp search",
+ "description": "Label after the search input field in the editor shown on Ctrl-F"
+ },
"sectionAdd": {
"message": "Add another section",
"description": "Label for the button to add a section"
diff --git a/edit.html b/edit.html
index a5b3e7b9..60f6100f 100644
--- a/edit.html
+++ b/edit.html
@@ -285,47 +285,47 @@
-
+
diff --git a/edit.js b/edit.js
index 62ea7f2a..469213f6 100644
--- a/edit.js
+++ b/edit.js
@@ -11,16 +11,44 @@ var propertyToCss = {urls: "url", urlPrefixes: "url-prefix", domains: "domain",
var CssToProperty = {"url": "urls", "url-prefix": "urlPrefixes", "domain": "domains", "regexp": "regexps"};
// templates
-var appliesToTemplate = document.createElement("li");
-appliesToTemplate.innerHTML = '' + t("appliesUrlOption") + ' ' + t("appliesUrlPrefixOption") + ' ' + t("appliesDomainOption") + ' ' + t("appliesRegexpOption") + ' ' + t("appliesRemove") + ' ' + t("appliesAdd") + ' ';
+var appliesToTemplate = tHTML('\
+ \
+ \
+ \
+ \
+ \
+ \
+ \
+ \
+ \
+ \
+ \
+');
-var appliesToEverythingTemplate = document.createElement("li");
-appliesToEverythingTemplate.className = "applies-to-everything";
-appliesToEverythingTemplate.innerHTML = t("appliesToEverything") + ' ' + t("appliesSpecify") + ' ';
+var appliesToEverythingTemplate = tHTML('\
+ \
+ \
+ \
+');
-var sectionTemplate = document.createElement("div");
-sectionTemplate.innerHTML = '' + t('sectionCode') + ' ' + t("appliesLabel") + ' ' + t('sectionRemove') + ' ' + t('sectionAdd') + ' ';
+var sectionTemplate = tHTML('\
+ \
+
\
+
\
+
\
+
\
+
\
+ \
+ \
+
\
+
\
+
\
+
\
+
\
+');
+var findTemplate = t("search") + ': ' +
+ '(' + t("searchRegexp") + ') ';
// make querySelectorAll enumeration code readable
["forEach", "some", "indexOf"].forEach(function(method) {
@@ -153,7 +181,6 @@ function initCodeMirror() {
controlOptions = ["smartIndent", "indentWithTabs", "tabSize", "keyMap", "lineWrapping"];
controlOptions.forEach(function(option) {
controlPrefs["editor." + option] = CM.defaults[option];
- tE(option + "-label", "cm_" + option);
});
loadPrefs(controlPrefs);
@@ -417,7 +444,7 @@ function setupGlobalSearch() {
function find(activeCM) {
var originalOpenDialog = activeCM.openDialog;
activeCM.openDialog = function(template, callback, options) {
- originalOpenDialog.call(activeCM, template, function(query) {
+ originalOpenDialog.call(activeCM, findTemplate, function(query) {
activeCM.openDialog = originalOpenDialog;
callback(query);
var state = activeCM.state.search;
@@ -554,7 +581,6 @@ function nextPrevBuffer(cm, direction) {
window.addEventListener("load", init, false);
function init() {
- tE("sections-help", "helpAlt", "alt");
var params = getParams();
if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses
// This is an add
@@ -582,7 +608,7 @@ function init() {
function initWithStyle(style) {
document.getElementById("name").value = style.name;
document.getElementById("enabled").checked = style.enabled == "true";
- document.getElementById("heading").innerHTML = t("editStyleHeading");
+ tE("heading", "editStyleHeading", null, false);
// if this was done in response to an update, we need to clear existing sections
document.querySelectorAll("#sections > div").forEach(function(div) {
div.parentNode.removeChild(div);
@@ -781,14 +807,6 @@ chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
}
});
-tE("name", "styleMissingName", "placeholder");
-tE("enabled-label", "styleEnabledLabel");
-tE("to-mozilla", "styleToMozillaFormat");
-tE("save-button", "styleSaveLabel");
-tE("cancel-button", "styleCancelEditLabel");
-tE("sections-heading", "styleSectionsTitle");
-tE("options-heading", "optionsHeading");
-
document.getElementById("to-mozilla").addEventListener("click", showMozillaFormat, false);
document.getElementById("to-mozilla-help").addEventListener("click", showToMozillaHelp, false);
document.getElementById("save-button").addEventListener("click", save, false);
diff --git a/localization.js b/localization.js
index b9ebf07a..18fd9059 100644
--- a/localization.js
+++ b/localization.js
@@ -1,3 +1,5 @@
+tDocLoader();
+
function t(key, params) {
var s = chrome.i18n.getMessage(key, params)
if (s == "") {
@@ -17,3 +19,55 @@ function tE(id, key, attr, esc) {
document.getElementById(id).innerHTML = t(key);
}
}
+
+function tHTML(html) {
+ var node = document.createElement("div");
+ node.innerHTML = html.replace(/>\s+<'); // spaces are removed; use for an explicit space
+ tNodeList(node.querySelectorAll("*"));
+ var child = node.removeChild(node.firstElementChild);
+ node.remove();
+ return child;
+}
+
+function tNodeList(nodes) {
+ for (var n = 0; n < nodes.length; n++) {
+ var node = nodes[n];
+ if (node.nodeType != 1) { // not an ELEMENT_NODE
+ continue;
+ }
+ for (var a = 0; a < node.attributes.length; a++) {
+ var name = node.attributes[a].nodeName;
+ if (name.indexOf("i18n-") != 0) {
+ continue;
+ }
+ name = name.substr(5); // "i18n-".length
+ var value = t(node.attributes[a].nodeValue);
+ switch (name) {
+ case "text":
+ node.insertBefore(document.createTextNode(value), node.firstChild);
+ break;
+ case "html":
+ node.insertAdjacentHTML("afterbegin", value);
+ break;
+ default:
+ node.setAttribute(name, value);
+ }
+ }
+ }
+}
+
+function tDocLoader() {
+ // localize HEAD
+ tNodeList(document.querySelectorAll("*"));
+
+ // localize BODY
+ var observer = new MutationObserver(function(mutations) {
+ for (var m = 0; m < mutations.length; m++) {
+ tNodeList(mutations[m].addedNodes);
+ }
+ });
+ observer.observe(document, {subtree: true, childList: true});
+ document.addEventListener("DOMContentLoaded", function() {
+ observer.disconnect();
+ });
+}
diff --git a/manage.html b/manage.html
index 06496791..b4b0c34f 100644
--- a/manage.html
+++ b/manage.html
@@ -1,6 +1,6 @@
-
+