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: Fixed the progress indicator and small fixes Created Feb. 4, 2016, 5:43 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
« background.js ('K') | « background.js ('k') | locale/en-US/options.json » ('j') | no next file with comments »
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 runtime 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,20 @@
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()];
+
+ var dateParts = dateParts.map(function(datePart)
+ {
+ return datePart < 10 ? "0" + datePart : datePart;
+ });
+
+ return [dateParts.splice(0, 3).join("-"), dateParts.join(":")];
+}
+
// Fill in the strings as soon as possible
window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
« background.js ('K') | « background.js ('k') | locale/en-US/options.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld