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

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

Issue 11533106: Prepared adblockplus for Safari (Closed)
Left Patch Set: Added another js file for safari and chrome Created Oct. 21, 2013, 8:14 p.m.
Right Patch Set: Made first run page always (also in FF) generated Created Oct. 31, 2013, 10:45 a.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
« no previous file with change/comment | « chrome/content/ui/firstRun.js ('k') | chrome/locale/en-US/firstRun.properties » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 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 var i18n; 18 var i18n;
19 19
20 if (typeof ext != "undefined") 20 if (typeof ext != "undefined")
21 i18n = ext.i18n; 21 i18n = ext.i18n;
22 else if (typeof chrome != "undefined") 22 else if (typeof chrome != "undefined")
23 // TODO: This check only exist for backwards compatibility, while the Safari
24 // port isn't merged into the adblockpluschrome repo. So this branch should
25 // be removed when the Safari port was merged.
23 i18n = chrome.i18n; 26 i18n = chrome.i18n;
24 else 27 else
25 { 28 {
26 // Using Firefox' approach on i18n instead 29 // Using Firefox' approach on i18n instead
27 30
28 // Randomize URI to work around bug 719376 31 // Randomize URI to work around bug 719376
29 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); 32 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, '');
30 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + 33 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName +
31 ".properties?" + Math.random()); 34 ".properties?" + Math.random());
32 35
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 catch(e) 79 catch(e)
77 { 80 {
78 Cu.reportError(e); 81 Cu.reportError(e);
79 return "Missing translation: " + key; 82 return "Missing translation: " + key;
80 } 83 }
81 } 84 }
82 }; 85 };
83 })(); 86 })();
84 } 87 }
85 88
86 // Loads and inserts i18n strings into matching elements. Any inner HTML already in the 89 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is
87 // element is parsed as JSON and used as parameters to substitute into placehold ers in the 90 // parsed as JSON and used as parameters to substitute into placeholders in the i18n
88 // i18n message. 91 // message.
89 function loadI18nStrings() 92 i18n.setElementText = function(element, stringName, arguments)
90 { 93 {
91 function processString(str, element) 94 function processString(str, element)
92 { 95 {
93 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str); 96 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
94 if (match) 97 if (match)
95 { 98 {
96 processString(match[1], element); 99 processString(match[1], element);
97 100
98 var e = document.createElement(match[2]); 101 var e = document.createElement(match[2]);
99 processString(match[3], e); 102 processString(match[3], e);
100 element.appendChild(e); 103 element.appendChild(e);
101 104
102 processString(match[4], element); 105 processString(match[4], element);
103 } 106 }
104 else 107 else
105 element.appendChild(document.createTextNode(str)); 108 element.appendChild(document.createTextNode(str));
106 } 109 }
107 110
111 while (element.lastChild)
112 element.removeChild(element.lastChild);
113 processString(i18n.getMessage(stringName, arguments), element);
114 }
115
116 // Loads i18n strings
117 function loadI18nStrings()
118 {
108 var nodes = document.querySelectorAll("[class^='i18n_']"); 119 var nodes = document.querySelectorAll("[class^='i18n_']");
109 for(var i = 0; i < nodes.length; i++) 120 for(var i = 0; i < nodes.length; i++)
110 { 121 {
111 var node = nodes[i]; 122 var node = nodes[i];
112 var arguments = JSON.parse("[" + node.textContent + "]"); 123 var arguments = JSON.parse("[" + node.textContent + "]");
113 if (arguments.length == 0) 124 if (arguments.length == 0)
114 arguments = null; 125 arguments = null;
115 126
116 var className = node.className; 127 var className = node.className;
117 if (className instanceof SVGAnimatedString) 128 if (className instanceof SVGAnimatedString)
118 className = className.animVal; 129 className = className.animVal;
119 var stringName = className.split(/\s/)[0].substring(5); 130 var stringName = className.split(/\s/)[0].substring(5);
120 131
121 while (node.lastChild) 132 i18n.setElementText(node, stringName, arguments);
122 node.removeChild(node.lastChild);
123 processString(i18n.getMessage(stringName, arguments), node);
124 } 133 }
125 } 134 }
126 135
127 // Provides a more readable string of the current date and time 136 // Provides a more readable string of the current date and time
128 function i18n_timeDateStrings(when) 137 function i18n_timeDateStrings(when)
129 { 138 {
130 var d = new Date(when); 139 var d = new Date(when);
131 var timeString = d.toLocaleTimeString(); 140 var timeString = d.toLocaleTimeString();
132 141
133 var now = new Date(); 142 var now = new Date();
134 if (d.toDateString() == now.toDateString()) 143 if (d.toDateString() == now.toDateString())
135 return [timeString]; 144 return [timeString];
136 else 145 else
137 return [timeString, d.toLocaleDateString()]; 146 return [timeString, d.toLocaleDateString()];
138 } 147 }
139 148
140 // Fill in the strings as soon as possible 149 // Fill in the strings as soon as possible
141 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); 150 window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld