-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic-text.html
58 lines (48 loc) · 1.45 KB
/
dynamic-text.html
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
54
55
56
57
58
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dynamic text</title>
<script>
const libUrl = location.hostname.includes('localhost')
? '../../ultimate-i18n-js/lib/index.js'
: 'https://cdn.jsdelivr.net/npm/[email protected]/lib/index.min.js';
document.write(`<script src="${libUrl}"><\/script>`);
</script>
</head>
<body>
<div id="time"></div>
<script>
const placeholder = document.getElementById('time');
function timePad(value) {
return String(value).padStart(2, '0');
}
function fill() {
const now = new Date();
const time = `${timePad(now.getHours())}:${timePad(now.getMinutes())}:${timePad(now.getSeconds())}`;
const newText = document.createElement('span');
newText.innerText = `Current time: ${time}`;
newText.setAttribute('i18n-pl', `Aktualny czas: ${time}`);
newText.setAttribute('i18n-es', `Tiempo actual: ${time}`);
if (placeholder.children.length === 0) {
placeholder.appendChild(newText);
} else {
placeholder.children[0].replaceWith(newText);
}
}
fill();
setInterval(fill, 1000);
</script>
<p>
<span
i18n-pl="Zmień język:"
i18n-es="Cambiar idioma:">
Change language:
</span>
<button onclick="UltimateI18n.set('en');">EN</button>
<button onclick="UltimateI18n.set('es');">ES</button>
<button onclick="UltimateI18n.set('pl');">PL</button>
</p>
</body>
</html>