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

Side by Side Diff: i18n.js

Issue 6289768170127360: Issue 2067 - Unify logic retrieving the UI locale (Closed)
Patch Set: Fixed: There is no ext.i18n in the background page on Firefox Created March 2, 2015, 11:55 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | messageResponder.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 // This variable should no longer be necessary once options.js in Chrome 18 // This variable should no longer be necessary once options.js in Chrome
19 // accesses ext.i18n directly. 19 // accesses ext.i18n directly.
20 var i18n = ext.i18n; 20 var i18n = ext.i18n;
21 21
22 if (ext.i18n.getMessage("@@ui_locale")) 22 // Getting UI locale cannot be done synchronously on Firefox,
23 { 23 // requires messaging the background page. For Chrome and Safari,
24 document.documentElement.lang = ext.i18n.getMessage("@@ui_locale").replace(/_/ g, "-"); 24 // we could get the UI locale here, but would need to duplicate
25 document.documentElement.dir = ext.i18n.getMessage("@@bidi_dir"); 25 // the logic implemented in Utils.appLocale.
26 } 26 ext.backgroundPage.sendMessage(
27 else 27 {
28 {
29 // Getting UI locale cannot be done synchronously on Firefox, requires
30 // messaging the background page.
31 ext.backgroundPage.sendMessage({
32 type: "app.get", 28 type: "app.get",
33 what: "localeInfo" 29 what: "localeInfo"
34 }, function(localeInfo) 30 },
31 function(localeInfo)
35 { 32 {
36 document.documentElement.lang = localeInfo.locale; 33 document.documentElement.lang = localeInfo.locale;
37 document.documentElement.dir = localeInfo.isRTL ? "rtl" : "ltr"; 34 document.documentElement.dir = localeInfo.bidiDir;
38 }); 35 }
39 } 36 );
40 37
41 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is 38 // Inserts i18n strings into matching elements. Any inner HTML already in the el ement is
42 // parsed as JSON and used as parameters to substitute into placeholders in the i18n 39 // parsed as JSON and used as parameters to substitute into placeholders in the i18n
43 // message. 40 // message.
44 ext.i18n.setElementText = function(element, stringName, arguments) 41 ext.i18n.setElementText = function(element, stringName, arguments)
45 { 42 {
46 function processString(str, element) 43 function processString(str, element)
47 { 44 {
48 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str); 45 var match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
49 if (match) 46 if (match)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 90
94 var now = new Date(); 91 var now = new Date();
95 if (d.toDateString() == now.toDateString()) 92 if (d.toDateString() == now.toDateString())
96 return [timeString]; 93 return [timeString];
97 else 94 else
98 return [timeString, d.toLocaleDateString()]; 95 return [timeString, d.toLocaleDateString()];
99 } 96 }
100 97
101 // Fill in the strings as soon as possible 98 // Fill in the strings as soon as possible
102 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); 99 window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
OLDNEW
« no previous file with comments | « no previous file | messageResponder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld