| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 } | 58 } |
| 59 | 59 |
| 60 while (element.lastChild) | 60 while (element.lastChild) |
| 61 element.removeChild(element.lastChild); | 61 element.removeChild(element.lastChild); |
| 62 processString(ext.i18n.getMessage(stringName, arguments), element); | 62 processString(ext.i18n.getMessage(stringName, arguments), element); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Loads i18n strings | 65 // Loads i18n strings |
| 66 function loadI18nStrings() | 66 function loadI18nStrings() |
| 67 { | 67 { |
| 68 var nodes = document.querySelectorAll("[class^='i18n_']"); | 68 function addI18nStringsToElements(nodes) |
|
Thomas Greiner
2016/01/25 15:40:29
Detail: You're calling them "elements" everywhere
saroyanm
2016/01/26 18:36:16
Done.
| |
| 69 for(var i = 0; i < nodes.length; i++) | |
| 70 { | 69 { |
| 71 var node = nodes[i]; | 70 for(var i = 0; i < nodes.length; i++) |
| 72 var arguments = JSON.parse("[" + node.textContent + "]"); | 71 { |
| 73 if (arguments.length == 0) | 72 var node = nodes[i]; |
| 74 arguments = null; | 73 var arguments = JSON.parse("[" + node.textContent + "]"); |
| 74 if (arguments.length == 0) | |
| 75 arguments = null; | |
| 75 | 76 |
| 76 var className = node.className; | 77 var className = node.className; |
| 77 if (className instanceof SVGAnimatedString) | 78 if (className instanceof SVGAnimatedString) |
| 78 className = className.animVal; | 79 className = className.animVal; |
| 79 var stringName = className.split(/\s/)[0].substring(5); | 80 var stringName = className.split(/\s/)[0].substring(5); |
| 80 | 81 |
| 81 ext.i18n.setElementText(node, stringName, arguments); | 82 ext.i18n.setElementText(node, stringName, arguments); |
| 83 } | |
| 84 } | |
| 85 addI18nStringsToElements(document.querySelectorAll("[class^='i18n_']")); | |
|
Thomas Greiner
2016/01/25 15:40:29
Detail: You're always calling this function using
saroyanm
2016/01/26 18:36:16
Done.
| |
| 86 var templates = document.querySelectorAll("template"); | |
|
Thomas Greiner
2016/01/25 15:40:30
Detail: Please add a short comment to explain why
saroyanm
2016/01/26 18:36:17
Done.
| |
| 87 for (var i = 0; i < templates.length; i++) | |
| 88 { | |
| 89 var nodes = templates[i].content.querySelectorAll("[class^='i18n_']"); | |
| 90 if (nodes.length > 0) | |
| 91 addI18nStringsToElements(nodes); | |
| 82 } | 92 } |
| 83 } | 93 } |
| 84 | 94 |
| 85 // Provides a more readable string of the current date and time | 95 // Provides a more readable string of the current date and time |
| 86 function i18n_timeDateStrings(when) | 96 function i18n_timeDateStrings(when) |
| 87 { | 97 { |
| 88 var d = new Date(when); | 98 var d = new Date(when); |
| 89 var timeString = d.toLocaleTimeString(); | 99 var timeString = d.toLocaleTimeString(); |
| 90 | 100 |
| 91 var now = new Date(); | 101 var now = new Date(); |
| 92 if (d.toDateString() == now.toDateString()) | 102 if (d.toDateString() == now.toDateString()) |
| 93 return [timeString]; | 103 return [timeString]; |
| 94 else | 104 else |
| 95 return [timeString, d.toLocaleDateString()]; | 105 return [timeString, d.toLocaleDateString()]; |
| 96 } | 106 } |
| 97 | 107 |
| 98 // Fill in the strings as soon as possible | 108 // Fill in the strings as soon as possible |
| 99 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); | 109 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); |
| OLD | NEW |