OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
| 18 (function(global) |
| 19 { |
| 20 const Ci = Components.interfaces; |
| 21 const Cu = Components.utils; |
| 22 |
| 23 if (!global.ext) |
| 24 global.ext = {}; |
| 25 |
| 26 /* Message passing */ |
| 27 global.ext.onMessage = new global.ext._EventTarget(); |
| 28 |
| 29 global.ext.backgroundPage = new global.ext._MessageProxy( |
| 30 window.QueryInterface(Ci.nsIInterfaceRequestor) |
| 31 .getInterface(Ci.nsIDocShell) |
| 32 .QueryInterface(Ci.nsIInterfaceRequestor) |
| 33 .getInterface(Ci.nsIContentFrameMessageManager), |
| 34 global.ext.onMessage); |
| 35 window.addEventListener("unload", function() |
| 36 { |
| 37 global.ext.backgroundPage._disconnect(); |
| 38 }, false); |
| 39 |
| 40 /* i18n */ |
| 41 global.ext.i18n = (function() |
| 42 { |
| 43 var Services = Cu.import("resource://gre/modules/Services.jsm", null).Servic
es; |
| 44 var pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, ""); |
| 45 |
| 46 // Randomize URI to work around bug 719376 |
| 47 var stringBundle = Services.strings.createBundle("chrome://adblockplus/local
e/" + pageName + |
| 48 ".properties?" + Math.random()); |
| 49 |
| 50 function getI18nMessage(key) |
| 51 { |
| 52 return { |
| 53 "message": stringBundle.GetStringFromName(key) |
| 54 }; |
| 55 } |
| 56 |
| 57 function getText(message, args) |
| 58 { |
| 59 var text = message.message; |
| 60 var placeholders = message.placeholders; |
| 61 |
| 62 if (!args || !placeholders) |
| 63 return text; |
| 64 |
| 65 for (var key in placeholders) |
| 66 { |
| 67 var content = placeholders[key].content; |
| 68 if (!content) |
| 69 continue; |
| 70 |
| 71 var index = parseInt(content.slice(1), 10); |
| 72 if (isNaN(index)) |
| 73 continue; |
| 74 |
| 75 var replacement = args[index - 1]; |
| 76 if (typeof replacement === "undefined") |
| 77 continue; |
| 78 |
| 79 text = text.split("$" + key + "$").join(replacement); |
| 80 } |
| 81 return text; |
| 82 } |
| 83 |
| 84 return { |
| 85 noSpecialMessages: true, |
| 86 |
| 87 getMessage: function(key, args) |
| 88 { |
| 89 try{ |
| 90 var message = getI18nMessage(key); |
| 91 return getText(message, args); |
| 92 } |
| 93 catch(e) |
| 94 { |
| 95 Cu.reportError(e); |
| 96 return "Missing translation: " + key; |
| 97 } |
| 98 } |
| 99 }; |
| 100 })(); |
| 101 })(this); |
OLD | NEW |