-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathi18n.js
44 lines (40 loc) · 1.6 KB
/
i18n.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Loads and inserts i18n strings into matching elements. Any inner HTML already in the
// element is parsed as JSON and used as parameters to substitute into placeholders in the
// i18n message.
function loadI18nStrings() {
var nodes = document.querySelectorAll("[class^='i18n_']");
for(var i = 0; i < nodes.length; i++) {
var arguments = JSON.parse("[" + nodes[i].innerHTML + "]");
if(arguments.length > 0)
nodes[i].innerHTML = chrome.i18n.getMessage(nodes[i].className.substring(5), arguments);
else
nodes[i].innerHTML = chrome.i18n.getMessage(nodes[i].className.substring(5));
}
}
function i18n_time(h, m) {
var locale = chrome.i18n.getMessage("@@ui_locale");
if(m < 10) m = "0" + m;
if(locale == "fr") {
return h + "h" + m;
} else {
var ampm = "a.m.";
if(h >= 12) {
h -= 12;
ampm = "p.m.";
}
if(h == 0) h = 12;
return(h + ":" + m + " " + ampm);
}
}
// Provides a more readable string of the current date and time
function i18n_timeDateStrings(when) {
var monthNames = JSON.parse(chrome.i18n.getMessage("month_names"));
var d = new Date(when);
var timeString = i18n_time(d.getHours(), d.getMinutes());
var now = new Date();
if(d.getDate() == now.getDate() && d.getMonth() == now.getMonth() && d.getFullYear() == now.getFullYear())
dateString = chrome.i18n.getMessage("today");
else
dateString = chrome.i18n.getMessage("date_format", [d.getDate(), monthNames[d.getMonth()], d.getFullYear()]);
return [timeString, dateString];
}