| LEFT | RIGHT | 
|---|
| 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-2016 Eyeo GmbH | 3  * Copyright (C) 2006-2016 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 12 matching lines...) Expand all  Loading... | 
| 23 | 23 | 
| 24 // Getting UI locale cannot be done synchronously on Firefox, | 24 // Getting UI locale cannot be done synchronously on Firefox, | 
| 25 // requires messaging the background page. For Chrome and Safari, | 25 // requires messaging the background page. For Chrome and Safari, | 
| 26 // we could get the UI locale here, but would need to duplicate | 26 // we could get the UI locale here, but would need to duplicate | 
| 27 // the logic implemented in Utils.appLocale. | 27 // the logic implemented in Utils.appLocale. | 
| 28 ext.backgroundPage.sendMessage( | 28 ext.backgroundPage.sendMessage( | 
| 29   { | 29   { | 
| 30     type: "app.get", | 30     type: "app.get", | 
| 31     what: "localeInfo" | 31     what: "localeInfo" | 
| 32   }, | 32   }, | 
| 33   localeInfo => | 33   (localeInfo) => | 
| 34   { | 34   { | 
| 35     document.documentElement.lang = localeInfo.locale; | 35     document.documentElement.lang = localeInfo.locale; | 
| 36     document.documentElement.dir = localeInfo.bidiDir; | 36     document.documentElement.dir = localeInfo.bidiDir; | 
| 37   } | 37   } | 
| 38 ); | 38 ); | 
| 39 | 39 | 
| 40 // Inserts i18n strings into matching elements. Any inner HTML already | 40 // Inserts i18n strings into matching elements. Any inner HTML already | 
| 41 // in the element is parsed as JSON and used as parameters to | 41 // in the element is parsed as JSON and used as parameters to | 
| 42 // substitute into placeholders in the i18n message. | 42 // substitute into placeholders in the i18n message. | 
| 43 ext.i18n.setElementText = function(element, stringName, args) | 43 ext.i18n.setElementText = function(element, stringName, args) | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 63     element.removeChild(element.lastChild); | 63     element.removeChild(element.lastChild); | 
| 64   processString(ext.i18n.getMessage(stringName, args), element); | 64   processString(ext.i18n.getMessage(stringName, args), element); | 
| 65 }; | 65 }; | 
| 66 | 66 | 
| 67 // Loads i18n strings | 67 // Loads i18n strings | 
| 68 function loadI18nStrings() | 68 function loadI18nStrings() | 
| 69 { | 69 { | 
| 70   function addI18nStringsToElements(containerElement) | 70   function addI18nStringsToElements(containerElement) | 
| 71   { | 71   { | 
| 72     let elements = containerElement.querySelectorAll("[class^='i18n_']"); | 72     let elements = containerElement.querySelectorAll("[class^='i18n_']"); | 
| 73     for (let i = 0; i < elements.length; i++) | 73     for (let node of elements) | 
| 74     { | 74     { | 
| 75       let node = elements[i]; |  | 
| 76       let args = JSON.parse("[" + node.textContent + "]"); | 75       let args = JSON.parse("[" + node.textContent + "]"); | 
| 77       if (args.length == 0) | 76       if (args.length == 0) | 
| 78         args = null; | 77         args = null; | 
| 79 | 78 | 
| 80       let {className} = node; | 79       let {className} = node; | 
| 81       if (className instanceof SVGAnimatedString) | 80       if (className instanceof SVGAnimatedString) | 
| 82         className = className.animVal; | 81         className = className.animVal; | 
| 83       let stringName = className.split(/\s/)[0].substring(5); | 82       let stringName = className.split(/\s/)[0].substring(5); | 
| 84 | 83 | 
| 85       ext.i18n.setElementText(node, stringName, args); | 84       ext.i18n.setElementText(node, stringName, args); | 
| 86     } | 85     } | 
| 87   } | 86   } | 
| 88   addI18nStringsToElements(document); | 87   addI18nStringsToElements(document); | 
| 89   // Content of Template is not rendered on runtime so we need to add | 88   // Content of Template is not rendered on runtime so we need to add | 
| 90   // translation strings for each Template documentFragment content | 89   // translation strings for each Template documentFragment content | 
| 91   // individually. | 90   // individually. | 
| 92   let templates = document.querySelectorAll("template"); | 91   for (let template of document.querySelectorAll("template")) | 
| 93   for (let i = 0; i < templates.length; i++) | 92     addI18nStringsToElements(template.content); | 
| 94     addI18nStringsToElements(templates[i].content); |  | 
| 95 } | 93 } | 
| 96 | 94 | 
| 97 /* eslint-disable camelcase */ |  | 
| 98 // Provides a more readable string of the current date and time | 95 // Provides a more readable string of the current date and time | 
| 99 function i18n_timeDateStrings(when) | 96 function i18nTimeDateStrings(when) | 
| 100 { | 97 { | 
| 101   let d = new Date(when); | 98   let d = new Date(when); | 
| 102   let timeString = d.toLocaleTimeString(); | 99   let timeString = d.toLocaleTimeString(); | 
| 103 | 100 | 
| 104   let now = new Date(); | 101   let now = new Date(); | 
| 105   if (d.toDateString() == now.toDateString()) | 102   if (d.toDateString() == now.toDateString()) | 
| 106     return [timeString]; | 103     return [timeString]; | 
| 107   return [timeString, d.toLocaleDateString()]; | 104   return [timeString, d.toLocaleDateString()]; | 
| 108 } | 105 } | 
| 109 | 106 | 
| 110 // Formats date string to ["YYYY-MM-DD", "mm:ss"] format | 107 // Formats date string to ["YYYY-MM-DD", "mm:ss"] format | 
| 111 function i18n_formatDateTime(when) | 108 function i18nFormatDateTime(when) | 
| 112 { | 109 { | 
| 113   let date = new Date(when); | 110   let date = new Date(when); | 
| 114   let dateParts = [date.getFullYear(), date.getMonth() + 1, date.getDate(), | 111   let dateParts = [date.getFullYear(), date.getMonth() + 1, date.getDate(), | 
| 115                    date.getHours(), date.getMinutes()]; | 112                    date.getHours(), date.getMinutes()]; | 
| 116 | 113 | 
| 117   dateParts = dateParts.map( | 114   dateParts = dateParts.map( | 
| 118     datePart => datePart < 10 ? "0" + datePart : datePart | 115     (datePart) => datePart < 10 ? "0" + datePart : datePart | 
| 119   ); | 116   ); | 
| 120 | 117 | 
| 121   return [dateParts.splice(0, 3).join("-"), dateParts.join(":")]; | 118   return [dateParts.splice(0, 3).join("-"), dateParts.join(":")]; | 
| 122 } | 119 } | 
| 123 /* eslint-enable camelcase */ |  | 
| 124 | 120 | 
| 125 // Fill in the strings as soon as possible | 121 // Fill in the strings as soon as possible | 
| 126 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); | 122 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); | 
| LEFT | RIGHT | 
|---|