Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: i18n.js

Issue 8403145: First attempt at creating a first-run page (Closed)
Patch Set: Created Sept. 27, 2012, 8:47 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « firstRun.js ('k') | options.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Loads and inserts i18n strings into matching elements. Any inner HTML already in the 7 // 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 8 // element is parsed as JSON and used as parameters to substitute into placehold ers in the
9 // i18n message. 9 // i18n message.
10 function loadI18nStrings() { 10 function loadI18nStrings() {
11 var nodes = document.querySelectorAll("[class^='i18n_']"); 11 var nodes = document.querySelectorAll("[class^='i18n_']");
12 for(var i = 0; i < nodes.length; i++) { 12 for(var i = 0; i < nodes.length; i++) {
13 var arguments = JSON.parse("[" + nodes[i].textContent + "]"); 13 var arguments = JSON.parse("[" + nodes[i].textContent + "]");
14 var stringName = nodes[i].className.split(/\s/)[0].substring(5); 14 var className = nodes[i].className;
15 if (className instanceof SVGAnimatedString)
16 className = className.animVal;
17 var stringName = className.split(/\s/)[0].substring(5);
18 var prop = "innerHTML" in nodes[i] ? "innerHTML" : "textContent";
15 if(arguments.length > 0) 19 if(arguments.length > 0)
16 nodes[i].innerHTML = chrome.i18n.getMessage(stringName, arguments); 20 nodes[i][prop] = chrome.i18n.getMessage(stringName, arguments);
17 else 21 else
18 nodes[i].innerHTML = chrome.i18n.getMessage(stringName); 22 nodes[i][prop] = chrome.i18n.getMessage(stringName);
19 } 23 }
20 } 24 }
21 25
22 function i18n_time(h, m) { 26 function i18n_time(h, m) {
23 var locale = chrome.i18n.getMessage("@@ui_locale"); 27 var locale = chrome.i18n.getMessage("@@ui_locale");
24 if(m < 10) 28 if(m < 10)
25 m = "0" + m; 29 m = "0" + m;
26 if(locale == "fr") { 30 if(locale == "fr") {
27 return h + "h" + m; 31 return h + "h" + m;
28 } else { 32 } else {
(...skipping 12 matching lines...) Expand all
41 function i18n_timeDateStrings(when) { 45 function i18n_timeDateStrings(when) {
42 var d = new Date(when); 46 var d = new Date(when);
43 var timeString = d.toLocaleTimeString(); 47 var timeString = d.toLocaleTimeString();
44 48
45 var now = new Date(); 49 var now = new Date();
46 if (d.toDateString() == now.toDateString()) 50 if (d.toDateString() == now.toDateString())
47 return [timeString]; 51 return [timeString];
48 else 52 else
49 return [timeString, d.toLocaleDateString()]; 53 return [timeString, d.toLocaleDateString()];
50 } 54 }
55
56 // Fill in the strings as soon as possible
57 window.addEventListener("DOMContentLoaded", loadI18nStrings, true);
OLDNEW
« no previous file with comments | « firstRun.js ('k') | options.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld