OLD | NEW |
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
| 7 var i18n = chrome.i18n; |
| 8 |
7 // Loads and inserts i18n strings into matching elements. Any inner HTML already
in the | 9 // Loads and inserts i18n strings into matching elements. Any inner HTML already
in the |
8 // element is parsed as JSON and used as parameters to substitute into placehold
ers in the | 10 // element is parsed as JSON and used as parameters to substitute into placehold
ers in the |
9 // i18n message. | 11 // i18n message. |
10 function loadI18nStrings() | 12 function loadI18nStrings() |
11 { | 13 { |
12 var nodes = document.querySelectorAll("[class^='i18n_']"); | 14 var nodes = document.querySelectorAll("[class^='i18n_']"); |
13 for(var i = 0; i < nodes.length; i++) | 15 for(var i = 0; i < nodes.length; i++) |
14 { | 16 { |
15 var arguments = JSON.parse("[" + nodes[i].textContent + "]"); | 17 var arguments = JSON.parse("[" + nodes[i].textContent + "]"); |
16 var className = nodes[i].className; | 18 var className = nodes[i].className; |
17 if (className instanceof SVGAnimatedString) | 19 if (className instanceof SVGAnimatedString) |
18 className = className.animVal; | 20 className = className.animVal; |
19 var stringName = className.split(/\s/)[0].substring(5); | 21 var stringName = className.split(/\s/)[0].substring(5); |
20 var prop = "innerHTML" in nodes[i] ? "innerHTML" : "textContent"; | 22 var prop = "innerHTML" in nodes[i] ? "innerHTML" : "textContent"; |
21 if(arguments.length > 0) | 23 if(arguments.length > 0) |
22 nodes[i][prop] = chrome.i18n.getMessage(stringName, arguments); | 24 nodes[i][prop] = i18n.getMessage(stringName, arguments); |
23 else | 25 else |
24 nodes[i][prop] = chrome.i18n.getMessage(stringName); | 26 nodes[i][prop] = i18n.getMessage(stringName); |
25 } | 27 } |
26 } | 28 } |
27 | 29 |
28 // Provides a more readable string of the current date and time | 30 // Provides a more readable string of the current date and time |
29 function i18n_timeDateStrings(when) | 31 function i18n_timeDateStrings(when) |
30 { | 32 { |
31 var d = new Date(when); | 33 var d = new Date(when); |
32 var timeString = d.toLocaleTimeString(); | 34 var timeString = d.toLocaleTimeString(); |
33 | 35 |
34 var now = new Date(); | 36 var now = new Date(); |
35 if (d.toDateString() == now.toDateString()) | 37 if (d.toDateString() == now.toDateString()) |
36 return [timeString]; | 38 return [timeString]; |
37 else | 39 else |
38 return [timeString, d.toLocaleDateString()]; | 40 return [timeString, d.toLocaleDateString()]; |
39 } | 41 } |
40 | 42 |
41 // Fill in the strings as soon as possible | 43 // Fill in the strings as soon as possible |
42 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); | 44 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); |
OLD | NEW |