 Issue 10585038:
  First-run page (revisited)  (Closed)
    
  
    Issue 10585038:
  First-run page (revisited)  (Closed) 
  | 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-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; | 18 var i18n; | 
| 19 if (typeof chrome != "undefined") | 19 if (typeof chrome != "undefined") | 
| 20 { | 20 { | 
| 21 i18n = chrome.i18n; | 21 i18n = chrome.i18n; | 
| 22 } | 22 } | 
| 23 else | 23 else | 
| 24 { | 24 { | 
| 
Wladimir Palant
2013/05/27 11:02:00
Please add a comment noting that this is the Firef
 
Thomas Greiner
2013/05/27 13:03:16
Done.
 | |
| 25 // Using Firefox' approach on i18n instead | |
| 26 | |
| 25 // Randomize URI to work around bug 719376 | 27 // Randomize URI to work around bug 719376 | 
| 26 var stringBundle = Services.strings.createBundle("chrome://" + require("info") .addonName + "/locale/firstRun.properties?" + Math.random()); | 28 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); | 
| 
Wladimir Palant
2013/05/27 11:02:00
A relative URL should work here: "/locale/firstRun
 
Thomas Greiner
2013/05/27 13:03:16
Done.
 | |
| 29 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + | |
| 30 ".properties?" + Math.random()); | |
| 31 | |
| 27 function getI18nMessage(key) | 32 function getI18nMessage(key) | 
| 28 { | 33 { | 
| 29 return { | 34 return { | 
| 30 "message": stringBundle.GetStringFromName(key) | 35 "message": stringBundle.GetStringFromName(key) | 
| 31 }; | 36 }; | 
| 32 } | 37 } | 
| 33 | 38 | 
| 34 i18n = (function() | 39 i18n = (function() | 
| 35 { | 40 { | 
| 36 function getText(message, args) | 41 function getText(message, args) | 
| (...skipping 19 matching lines...) Expand all Loading... | |
| 56 continue; | 61 continue; | 
| 57 | 62 | 
| 58 text = text.split("$" + key + "$").join(replacement); | 63 text = text.split("$" + key + "$").join(replacement); | 
| 59 } | 64 } | 
| 60 return text; | 65 return text; | 
| 61 } | 66 } | 
| 62 | 67 | 
| 63 return { | 68 return { | 
| 64 getMessage: function(key, args) | 69 getMessage: function(key, args) | 
| 65 { | 70 { | 
| 66 var message = getI18nMessage(key); | 71 try{ | 
| 67 if (!message) | 72 var message = getI18nMessage(key); | 
| 73 return getText(message, args); | |
| 74 } | |
| 75 catch(e) | |
| 76 { | |
| 77 Cu.reportError(e); | |
| 68 return "Missing translation: " + key; | 78 return "Missing translation: " + key; | 
| 
Wladimir Palant
2013/05/27 11:02:00
This won't work - GetStringForName throws on missi
 
Thomas Greiner
2013/05/27 13:03:16
Done.
 | |
| 69 return getText(message, args); | 79 } | 
| 70 } | 80 } | 
| 71 }; | 81 }; | 
| 72 })(); | 82 })(); | 
| 73 } | 83 } | 
| 74 | 84 | 
| 75 // Loads and inserts i18n strings into matching elements. Any inner HTML already in the | 85 // Loads and inserts i18n strings into matching elements. Any inner HTML already in the | 
| 76 // element is parsed as JSON and used as parameters to substitute into placehold ers in the | 86 // element is parsed as JSON and used as parameters to substitute into placehold ers in the | 
| 77 // i18n message. | 87 // i18n message. | 
| 78 function loadI18nStrings() | 88 function loadI18nStrings() | 
| 79 { | 89 { | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 100 var timeString = d.toLocaleTimeString(); | 110 var timeString = d.toLocaleTimeString(); | 
| 101 | 111 | 
| 102 var now = new Date(); | 112 var now = new Date(); | 
| 103 if (d.toDateString() == now.toDateString()) | 113 if (d.toDateString() == now.toDateString()) | 
| 104 return [timeString]; | 114 return [timeString]; | 
| 105 else | 115 else | 
| 106 return [timeString, d.toLocaleDateString()]; | 116 return [timeString, d.toLocaleDateString()]; | 
| 107 } | 117 } | 
| 108 | 118 | 
| 109 // Fill in the strings as soon as possible | 119 // Fill in the strings as soon as possible | 
| 110 // Script could be injected after DOMContentLoaded fired | 120 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); | 
| 
Wladimir Palant
2013/05/27 11:02:00
Nope, it could not - if firstRun.js is coded clean
 
Thomas Greiner
2013/05/27 13:03:16
Done.
 | |
| 111 if (document.readyState != "loading") | |
| 112 loadI18nStrings(); | |
| 113 else | |
| 114 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); | |
| LEFT | RIGHT |