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

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

Issue 5137457368530944: Issue 1668 - Fixed direction on add-on pages for right-to-left scripts (Closed)
Left Patch Set: Created Dec. 8, 2014, 7:04 p.m.
Right Patch Set: Use browser APIs do determine direction Created Dec. 9, 2014, 5:36 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
« no previous file with change/comment | « chrome/content/ui/firstRun.js ('k') | chrome/skin/firstRun.css » ('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-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 var i18n; 18 var i18n;
19 var locale;
20 19
21 if (typeof ext != "undefined") 20 if (typeof ext != "undefined")
22 { 21 {
23 i18n = ext.i18n; 22 i18n = ext.i18n;
24 locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 23
24 document.documentElement.lang = ext.i18n.getMessage("@@ui_locale").replace(/_/ g, "-");
25 document.documentElement.dir = ext.i18n.getMessage("@@bidi_dir");
25 } 26 }
26 else 27 else
27 { 28 {
28 // Using Firefox' approach on i18n instead 29 // Using Firefox' approach on i18n instead
29 30
30 // Randomize URI to work around bug 719376 31 // Randomize URI to work around bug 719376
31 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); 32 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, '');
32 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + 33 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName +
33 ".properties?" + Math.random()); 34 ".properties?" + Math.random());
34 35
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 78 }
78 catch(e) 79 catch(e)
79 { 80 {
80 Cu.reportError(e); 81 Cu.reportError(e);
81 return "Missing translation: " + key; 82 return "Missing translation: " + key;
82 } 83 }
83 } 84 }
84 }; 85 };
85 })(); 86 })();
86 87
87 locale = require("utils").Utils.appLocale; 88 var Utils = require("utils").Utils;
89 document.documentElement.lang = Utils.appLocale;
90 document.documentElement.dir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr";
88 } 91 }
89 92
90 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is 93 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is
91 // parsed as JSON and used as parameters to substitute into placeholders in the i18n 94 // parsed as JSON and used as parameters to substitute into placeholders in the i18n
92 // message. 95 // message.
93 i18n.setElementText = function(element, stringName, arguments) 96 i18n.setElementText = function(element, stringName, arguments)
94 { 97 {
95 function processString(str, element) 98 function processString(str, element)
96 { 99 {
97 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str); 100 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 var d = new Date(when); 143 var d = new Date(when);
141 var timeString = d.toLocaleTimeString(); 144 var timeString = d.toLocaleTimeString();
142 145
143 var now = new Date(); 146 var now = new Date();
144 if (d.toDateString() == now.toDateString()) 147 if (d.toDateString() == now.toDateString())
145 return [timeString]; 148 return [timeString];
146 else 149 else
147 return [timeString, d.toLocaleDateString()]; 150 return [timeString, d.toLocaleDateString()];
148 } 151 }
149 152
150 function onDOMLoaded() 153 // Fill in the strings as soon as possible
151 { 154 window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
152 document.documentElement.lang = locale;
153
154 if (locale == "ar" || locale == "he")
155 document.documentElement.dir = "rtl";
156
157 loadI18nStrings();
158 }
159
160 window.addEventListener("DOMContentLoaded", onDOMLoaded, true);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld