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

Side by Side Diff: chrome/content/ui/i18n.js

Issue 5137457368530944: Issue 1668 - Fixed direction on add-on pages for right-to-left scripts (Closed)
Patch Set: Used -(webkit|moz)-border-start Created Dec. 8, 2014, 8:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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;
19 20
20 if (typeof ext != "undefined") 21 if (typeof ext != "undefined")
22 {
21 i18n = ext.i18n; 23 i18n = ext.i18n;
22 else if (typeof chrome != "undefined") 24 locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
Thomas Greiner 2014/12/09 10:29:04 What about Safari? We don't handle those predefine
Sebastian Noack 2014/12/09 10:41:13 We do handle @@ui_locale on Safari.
Thomas Greiner 2014/12/09 16:51:56 Sorry, missed that before. But why not simply use
Sebastian Noack 2014/12/09 17:40:19 Because in block.html on Chrome/Opera/Safari there
23 // TODO: This check only exist for backwards compatibility, while the Safari 25 }
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 26 else
28 { 27 {
29 // Using Firefox' approach on i18n instead 28 // Using Firefox' approach on i18n instead
30 29
31 // Randomize URI to work around bug 719376 30 // Randomize URI to work around bug 719376
32 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); 31 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, '');
33 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + 32 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName +
34 ".properties?" + Math.random()); 33 ".properties?" + Math.random());
35 34
36 function getI18nMessage(key) 35 function getI18nMessage(key)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return getText(message, args); 76 return getText(message, args);
78 } 77 }
79 catch(e) 78 catch(e)
80 { 79 {
81 Cu.reportError(e); 80 Cu.reportError(e);
82 return "Missing translation: " + key; 81 return "Missing translation: " + key;
83 } 82 }
84 } 83 }
85 }; 84 };
86 })(); 85 })();
86
87 locale = require("utils").Utils.appLocale;
87 } 88 }
88 89
89 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is 90 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is
90 // parsed as JSON and used as parameters to substitute into placeholders in the i18n 91 // parsed as JSON and used as parameters to substitute into placeholders in the i18n
91 // message. 92 // message.
92 i18n.setElementText = function(element, stringName, arguments) 93 i18n.setElementText = function(element, stringName, arguments)
93 { 94 {
94 function processString(str, element) 95 function processString(str, element)
95 { 96 {
96 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str); 97 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 var d = new Date(when); 140 var d = new Date(when);
140 var timeString = d.toLocaleTimeString(); 141 var timeString = d.toLocaleTimeString();
141 142
142 var now = new Date(); 143 var now = new Date();
143 if (d.toDateString() == now.toDateString()) 144 if (d.toDateString() == now.toDateString())
144 return [timeString]; 145 return [timeString];
145 else 146 else
146 return [timeString, d.toLocaleDateString()]; 147 return [timeString, d.toLocaleDateString()];
147 } 148 }
148 149
149 // Fill in the strings as soon as possible 150 function onDOMLoaded()
150 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); 151 {
152 document.documentElement.lang = locale;
153
154 if (locale == "ar" || locale == "he")
Thomas Greiner 2014/12/09 10:29:04 Similarly to above we could use `ext.i18n.getMessa
Sebastian Noack 2014/12/09 10:41:13 Is there a way to get the direction on Firefox? Ot
Thomas Greiner 2014/12/09 16:51:56 It could be handled the same way as "@@ui_locale"
Wladimir Palant 2014/12/09 16:59:08 Utils.chromeRegistry.isLocaleRTL("adblockplus") sh
Sebastian Noack 2014/12/09 17:40:19 Done. I'm going to implement @@bidi_dir for Safari
155 document.documentElement.dir = "rtl";
156
157 loadI18nStrings();
158 }
159
160 window.addEventListener("DOMContentLoaded", onDOMLoaded, true);
OLDNEW

Powered by Google App Engine
This is Rietveld