Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
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
| |
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 Loading... | |
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 Loading... | |
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") | |
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); | |
LEFT | RIGHT |