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

Delta Between Two Patch Sets: chrome/content/ui/i18n.js

Issue 5294633391226880: issue 1435 - Port popup.html from Chrome/Safari/Opera to Firefox (Closed)
Left Patch Set: Created Oct. 2, 2014, 7:48 a.m.
Right Patch Set: Created Oct. 27, 2014, 9:40 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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is 18 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is
19 // parsed as JSON and used as parameters to substitute into placeholders in the i18n 19 // parsed as JSON and used as parameters to substitute into placeholders in the i18n
20 // message. 20 // message.
21 ext.i18n.setElementText = function(element, stringName, arguments) 21 ext.i18n.setElementText = function(element, stringName, arguments)
22 { 22 {
23 function processString(str, element) 23 function processString(str, element)
24 { 24 {
25 let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str); 25 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
26 if (match) 26 if (match)
27 { 27 {
28 processString(match[1], element); 28 processString(match[1], element);
29 29
30 let e = document.createElement(match[2]); 30 var e = document.createElement(match[2]);
31 processString(match[3], e); 31 processString(match[3], e);
32 element.appendChild(e); 32 element.appendChild(e);
33 33
34 processString(match[4], element); 34 processString(match[4], element);
35 } 35 }
36 else 36 else
37 element.appendChild(document.createTextNode(str)); 37 element.appendChild(document.createTextNode(str));
38 } 38 }
39 39
40 while (element.lastChild) 40 while (element.lastChild)
41 element.removeChild(element.lastChild); 41 element.removeChild(element.lastChild);
42 processString(ext.i18n.getMessage(stringName, arguments), element); 42 processString(ext.i18n.getMessage(stringName, arguments), element);
43 } 43 }
44 44
45 // Loads i18n strings 45 // Loads i18n strings
46 function loadI18nStrings() 46 function loadI18nStrings()
47 { 47 {
48 let nodes = document.querySelectorAll("[class^='i18n_']"); 48 var nodes = document.querySelectorAll("[class^='i18n_']");
49 for(let i = 0; i < nodes.length; i++) 49 for(var i = 0; i < nodes.length; i++)
50 { 50 {
51 let node = nodes[i]; 51 var node = nodes[i];
52 let arguments = JSON.parse("[" + node.textContent + "]"); 52 var arguments = JSON.parse("[" + node.textContent + "]");
53 if (arguments.length == 0) 53 if (arguments.length == 0)
54 arguments = null; 54 arguments = null;
55 55
56 let className = node.className; 56 var className = node.className;
57 if (className instanceof SVGAnimatedString) 57 if (className instanceof SVGAnimatedString)
58 className = className.animVal; 58 className = className.animVal;
59 let stringName = className.split(/\s/)[0].substring(5); 59 var stringName = className.split(/\s/)[0].substring(5);
60 60
61 ext.i18n.setElementText(node, stringName, arguments); 61 ext.i18n.setElementText(node, stringName, arguments);
62 } 62 }
63 } 63 }
64 64
65 // Provides a more readable string of the current date and time 65 // Provides a more readable string of the current date and time
66 function i18n_timeDateStrings(when) 66 function i18n_timeDateStrings(when)
67 { 67 {
68 let d = new Date(when); 68 var d = new Date(when);
69 let timeString = d.toLocaleTimeString(); 69 var timeString = d.toLocaleTimeString();
70 70
71 let now = new Date(); 71 var now = new Date();
72 if (d.toDateString() == now.toDateString()) 72 if (d.toDateString() == now.toDateString())
73 return [timeString]; 73 return [timeString];
74 else 74 else
75 return [timeString, d.toLocaleDateString()]; 75 return [timeString, d.toLocaleDateString()];
76 } 76 }
77 77
78 // Fill in the strings as soon as possible 78 // Fill in the strings as soon as possible
79 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); 79 window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld