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: Changed text of legacy Safari warning as discussed Created Sept. 6, 2013, 4:54 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 = (window.ext && ext.i18n) || (window.chrome && chrome.i18n); 18 var i18n;
19 if (!i18n) 19
20 if (typeof ext != "undefined")
21 i18n = ext.i18n;
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.
26 i18n = chrome.i18n;
27 else
20 { 28 {
21 // Using Firefox' approach on i18n instead 29 // Using Firefox' approach on i18n instead
22 30
23 // Randomize URI to work around bug 719376 31 // Randomize URI to work around bug 719376
24 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); 32 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, '');
25 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + 33 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName +
26 ".properties?" + Math.random()); 34 ".properties?" + Math.random());
27 35
28 function getI18nMessage(key) 36 function getI18nMessage(key)
29 { 37 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 catch(e) 79 catch(e)
72 { 80 {
73 Cu.reportError(e); 81 Cu.reportError(e);
74 return "Missing translation: " + key; 82 return "Missing translation: " + key;
75 } 83 }
76 } 84 }
77 }; 85 };
78 })(); 86 })();
79 } 87 }
80 88
81 // 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
82 // 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
83 // i18n message. 91 // message.
84 function loadI18nStrings() 92 i18n.setElementText = function(element, stringName, arguments)
85 { 93 {
86 function processString(str, element) 94 function processString(str, element)
87 { 95 {
88 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str); 96 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
89 if (match) 97 if (match)
90 { 98 {
91 processString(match[1], element); 99 processString(match[1], element);
92 100
93 var e = document.createElement(match[2]); 101 var e = document.createElement(match[2]);
94 processString(match[3], e); 102 processString(match[3], e);
95 element.appendChild(e); 103 element.appendChild(e);
96 104
97 processString(match[4], element); 105 processString(match[4], element);
98 } 106 }
99 else 107 else
100 element.appendChild(document.createTextNode(str)); 108 element.appendChild(document.createTextNode(str));
101 } 109 }
102 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 {
103 var nodes = document.querySelectorAll("[class^='i18n_']"); 119 var nodes = document.querySelectorAll("[class^='i18n_']");
104 for(var i = 0; i < nodes.length; i++) 120 for(var i = 0; i < nodes.length; i++)
105 { 121 {
106 var node = nodes[i]; 122 var node = nodes[i];
107 var arguments = JSON.parse("[" + node.textContent + "]"); 123 var arguments = JSON.parse("[" + node.textContent + "]");
108 if (arguments.length == 0) 124 if (arguments.length == 0)
109 arguments = null; 125 arguments = null;
110 126
111 var className = node.className; 127 var className = node.className;
112 if (className instanceof SVGAnimatedString) 128 if (className instanceof SVGAnimatedString)
113 className = className.animVal; 129 className = className.animVal;
114 var stringName = className.split(/\s/)[0].substring(5); 130 var stringName = className.split(/\s/)[0].substring(5);
115 131
116 while (node.lastChild) 132 i18n.setElementText(node, stringName, arguments);
117 node.removeChild(node.lastChild);
118 processString(i18n.getMessage(stringName, arguments), node);
119 } 133 }
120 } 134 }
121 135
122 // Provides a more readable string of the current date and time 136 // Provides a more readable string of the current date and time
123 function i18n_timeDateStrings(when) 137 function i18n_timeDateStrings(when)
124 { 138 {
125 var d = new Date(when); 139 var d = new Date(when);
126 var timeString = d.toLocaleTimeString(); 140 var timeString = d.toLocaleTimeString();
127 141
128 var now = new Date(); 142 var now = new Date();
129 if (d.toDateString() == now.toDateString()) 143 if (d.toDateString() == now.toDateString())
130 return [timeString]; 144 return [timeString];
131 else 145 else
132 return [timeString, d.toLocaleDateString()]; 146 return [timeString, d.toLocaleDateString()];
133 } 147 }
134 148
135 // Fill in the strings as soon as possible 149 // Fill in the strings as soon as possible
136 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); 150 window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld