Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: i18n.js

Issue 29333819: Issue 2375 - Implement "Blocking lists" section in new options page (Closed)
Patch Set: Rebase to d12b18c2a168 Created Jan. 28, 2016, 1:38 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « background.js ('k') | locale/en-US/options.json » ('j') | options.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: i18n.js
===================================================================
--- a/i18n.js
+++ b/i18n.js
@@ -65,21 +65,30 @@
// Loads i18n strings
function loadI18nStrings()
{
- var nodes = document.querySelectorAll("[class^='i18n_']");
- for(var i = 0; i < nodes.length; i++)
+ function addI18nStringsToElements(containerElement)
{
- var node = nodes[i];
- var arguments = JSON.parse("[" + node.textContent + "]");
- if (arguments.length == 0)
- arguments = null;
+ var elements = containerElement.querySelectorAll("[class^='i18n_']");
+ for(var i = 0; i < elements.length; i++)
+ {
+ var node = elements[i];
+ var arguments = JSON.parse("[" + node.textContent + "]");
+ if (arguments.length == 0)
+ arguments = null;
- var className = node.className;
- if (className instanceof SVGAnimatedString)
- className = className.animVal;
- var stringName = className.split(/\s/)[0].substring(5);
+ var className = node.className;
+ if (className instanceof SVGAnimatedString)
+ className = className.animVal;
+ var stringName = className.split(/\s/)[0].substring(5);
- ext.i18n.setElementText(node, stringName, arguments);
+ ext.i18n.setElementText(node, stringName, arguments);
+ }
}
+ addI18nStringsToElements(document);
+ // Content of Template is not rendered on tuntime so we need to add
+ // translation strings for each Template documentFragment content individually
+ var templates = document.querySelectorAll("template");
+ for (var i = 0; i < templates.length; i++)
+ addI18nStringsToElements(templates[i].content);
}
// Provides a more readable string of the current date and time
@@ -95,5 +104,19 @@
return [timeString, d.toLocaleDateString()];
}
+// Formats date string to ["yyyy-mm-dd", "mm:ss"] format
+function i18n_formatDateTime(when)
+{
+ var date = new Date(when);
+ var dateParts = [date.getFullYear(), date.getMonth()+1, date.getDate(),
+ date.getHours(), date.getMinutes()];
+
+ for (var i = 0; i < dateParts.length; i++)
+ if (dateParts[i] < 10)
+ dateParts[i] = "0" + dateParts[i];
+
+ return [dateParts.splice(0, 3).join("-"), dateParts.splice(0, 2).join(":")];
+}
+
// Fill in the strings as soon as possible
window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
« no previous file with comments | « background.js ('k') | locale/en-US/options.json » ('j') | options.js » ('J')

Powered by Google App Engine
This is Rietveld