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

Delta Between Two Patch Sets: i18n.js

Issue 29333819: Issue 2375 - Implement "Blocking lists" section in new options page (Closed)
Left Patch Set: Addressed Thomas comments Created Jan. 22, 2016, 9:53 a.m.
Right Patch Set: Fixed the progress indicator and small fixes Created Feb. 4, 2016, 5:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 while (element.lastChild) 60 while (element.lastChild)
61 element.removeChild(element.lastChild); 61 element.removeChild(element.lastChild);
62 processString(ext.i18n.getMessage(stringName, arguments), element); 62 processString(ext.i18n.getMessage(stringName, arguments), element);
63 } 63 }
64 64
65 // Loads i18n strings 65 // Loads i18n strings
66 function loadI18nStrings() 66 function loadI18nStrings()
67 { 67 {
68 function addI18nStringsToElements(nodes) 68 function addI18nStringsToElements(containerElement)
Thomas Greiner 2016/01/25 15:40:29 Detail: You're calling them "elements" everywhere
saroyanm 2016/01/26 18:36:16 Done.
69 { 69 {
70 for(var i = 0; i < nodes.length; i++) 70 var elements = containerElement.querySelectorAll("[class^='i18n_']");
71 for(var i = 0; i < elements.length; i++)
71 { 72 {
72 var node = nodes[i]; 73 var node = elements[i];
73 var arguments = JSON.parse("[" + node.textContent + "]"); 74 var arguments = JSON.parse("[" + node.textContent + "]");
74 if (arguments.length == 0) 75 if (arguments.length == 0)
75 arguments = null; 76 arguments = null;
76 77
77 var className = node.className; 78 var className = node.className;
78 if (className instanceof SVGAnimatedString) 79 if (className instanceof SVGAnimatedString)
79 className = className.animVal; 80 className = className.animVal;
80 var stringName = className.split(/\s/)[0].substring(5); 81 var stringName = className.split(/\s/)[0].substring(5);
81 82
82 ext.i18n.setElementText(node, stringName, arguments); 83 ext.i18n.setElementText(node, stringName, arguments);
83 } 84 }
84 } 85 }
85 addI18nStringsToElements(document.querySelectorAll("[class^='i18n_']")); 86 addI18nStringsToElements(document);
Thomas Greiner 2016/01/25 15:40:29 Detail: You're always calling this function using
saroyanm 2016/01/26 18:36:16 Done.
87 // Content of Template is not rendered on runtime so we need to add
88 // translation strings for each Template documentFragment content individually
86 var templates = document.querySelectorAll("template"); 89 var templates = document.querySelectorAll("template");
Thomas Greiner 2016/01/25 15:40:30 Detail: Please add a short comment to explain why
saroyanm 2016/01/26 18:36:17 Done.
87 for (var i = 0; i < templates.length; i++) 90 for (var i = 0; i < templates.length; i++)
88 { 91 addI18nStringsToElements(templates[i].content);
89 var nodes = templates[i].content.querySelectorAll("[class^='i18n_']");
90 if (nodes.length > 0)
91 addI18nStringsToElements(nodes);
92 }
93 } 92 }
94 93
95 // Provides a more readable string of the current date and time 94 // Provides a more readable string of the current date and time
96 function i18n_timeDateStrings(when) 95 function i18n_timeDateStrings(when)
97 { 96 {
98 var d = new Date(when); 97 var d = new Date(when);
99 var timeString = d.toLocaleTimeString(); 98 var timeString = d.toLocaleTimeString();
100 99
101 var now = new Date(); 100 var now = new Date();
102 if (d.toDateString() == now.toDateString()) 101 if (d.toDateString() == now.toDateString())
103 return [timeString]; 102 return [timeString];
104 else 103 else
105 return [timeString, d.toLocaleDateString()]; 104 return [timeString, d.toLocaleDateString()];
106 } 105 }
107 106
107 // Formats date string to ["YYYY-MM-DD", "mm:ss"] format
108 function i18n_formatDateTime(when)
109 {
110 var date = new Date(when);
111 var dateParts = [date.getFullYear(), date.getMonth() + 1, date.getDate(),
112 date.getHours(), date.getMinutes()];
113
114 var dateParts = dateParts.map(function(datePart)
115 {
116 return datePart < 10 ? "0" + datePart : datePart;
117 });
118
119 return [dateParts.splice(0, 3).join("-"), dateParts.join(":")];
120 }
121
108 // Fill in the strings as soon as possible 122 // Fill in the strings as soon as possible
109 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); 123 window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld