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 |
Thomas Greiner
2016/02/01 18:52:35
Detail: Usually, you would write it as "YYYY-MM-DD
saroyanm
2016/02/03 14:04:25
Done.
|
+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); |