| 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 = (function() | 7 var i18n = (function() |
| 8 { | 8 { |
| 9 function getText(message, args) | 9 function getText(message, args) |
| 10 { | 10 { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 if (!message) | 41 if (!message) |
| 42 return "Missing translation: " + key; | 42 return "Missing translation: " + key; |
| 43 return getText(message, args); | 43 return getText(message, args); |
| 44 } | 44 } |
| 45 }; | 45 }; |
| 46 })(); | 46 })(); |
| 47 | 47 |
| 48 // Loads and inserts i18n strings into matching elements. Any inner HTML already
in the | 48 // Loads and inserts i18n strings into matching elements. Any inner HTML already
in the |
| 49 // element is parsed as JSON and used as parameters to substitute into placehold
ers in the | 49 // element is parsed as JSON and used as parameters to substitute into placehold
ers in the |
| 50 // i18n message. | 50 // i18n message. |
| 51 function loadI18nStrings() { | 51 function loadI18nStrings() |
| 52 { |
| 52 var nodes = document.querySelectorAll("[class^='i18n_']"); | 53 var nodes = document.querySelectorAll("[class^='i18n_']"); |
| 53 for(var i = 0; i < nodes.length; i++) { | 54 for(var i = 0; i < nodes.length; i++) |
| 55 { |
| 54 var arguments = JSON.parse("[" + nodes[i].textContent + "]"); | 56 var arguments = JSON.parse("[" + nodes[i].textContent + "]"); |
| 55 var className = nodes[i].className; | 57 var className = nodes[i].className; |
| 56 var stringName = className.split(/\s/)[0].substring(5); | 58 var stringName = className.split(/\s/)[0].substring(5); |
| 57 var prop = "innerHTML" in nodes[i] ? "innerHTML" : "textContent"; | 59 var prop = "innerHTML" in nodes[i] ? "innerHTML" : "textContent"; |
| 58 if(arguments.length > 0) | 60 if(arguments.length > 0) |
| 59 nodes[i][prop] = i18n.getMessage(stringName, arguments); | 61 nodes[i][prop] = i18n.getMessage(stringName, arguments); |
| 60 else | 62 else |
| 61 nodes[i][prop] = i18n.getMessage(stringName); | 63 nodes[i][prop] = i18n.getMessage(stringName); |
| 62 } | 64 } |
| 63 } | 65 } |
| 64 | 66 |
| 65 // Provides a more readable string of the current date and time | 67 // Provides a more readable string of the current date and time |
| 66 function i18n_timeDateStrings(when) { | 68 function i18n_timeDateStrings(when) |
| 69 { |
| 67 var d = new Date(when); | 70 var d = new Date(when); |
| 68 var timeString = d.toLocaleTimeString(); | 71 var timeString = d.toLocaleTimeString(); |
| 69 | 72 |
| 70 var now = new Date(); | 73 var now = new Date(); |
| 71 if (d.toDateString() == now.toDateString()) | 74 if (d.toDateString() == now.toDateString()) |
| 72 return [timeString]; | 75 return [timeString]; |
| 73 else | 76 else |
| 74 return [timeString, d.toLocaleDateString()]; | 77 return [timeString, d.toLocaleDateString()]; |
| 75 } | 78 } |
| 76 | 79 |
| 77 // Fill in the strings as soon as possible | 80 // Fill in the strings as soon as possible |
| 78 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); | 81 window.addEventListener("DOMContentLoaded", loadI18nStrings, true); |
| OLD | NEW |