-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (46 loc) · 1.64 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
import { ngettext, msgid, t, addLocale, useLocale } from 'c-3po';
export const view = (hours, minutes, seconds) => {
const hoursTxt = ngettext(msgid`${hours} hour`, `${hours} hours`, hours);
const minutesTxt = ngettext(msgid`${minutes} minute`, `${minutes} minutes`, minutes);
const secondsTxt = ngettext(msgid`${seconds} second`, `${seconds} seconds`, seconds);
return `
<ul>
<li>${ t`Choose locale` }</li>
<li><a href="${HOST}/">en</a></li>
<li><a href="${HOST}/uk">uk</a></li>
</ul>
<h1>${ t`webpack with c-3po localization demo` }</h1>
<h2>${ t`Current time is` }</h2>
<h3>${hoursTxt} ${minutesTxt} ${secondsTxt}</h3>
`
};
if (typeof document !== 'undefined') {
if (LOCALES_DATA !== null && LOCALES_DATA[LOCALE]) {
addLocale(LOCALE, LOCALES_DATA[LOCALE]);
useLocale(LOCALE);
}
const content = document.getElementById('content');
setInterval(() => {
const date = new Date();
content.innerHTML = view(date.getHours(), date.getMinutes(), date.getSeconds());
}, 1000);
}
export default () => {
const date = new Date();
const viewStr = view(date.getHours(), date.getMinutes(), date.getSeconds());
return `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>c-3po with webpack demo</title>
</head>
<style>
li { display: inline; margin: 0, padding: 0 }
ul { margin: 0; padding: 0 }
</style>
<body>
<div id="content">${viewStr}</div>
<script src='./app.js' type='text/javascript'></script>
</body>
</html>`
};