-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup-test.html
72 lines (60 loc) · 2.03 KB
/
rollup-test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.4/fetch.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@phensley/[email protected]/dist/cldrengine.umd.js" crossorigin="anonymous"></script>
<script src="./sqsptemplate2.umd.js"></script>
</head>
<body>
<div id="out"></div>
<script>
function asyncLoader(language) {
const baseurl = 'https://cdn.jsdelivr.net/npm/@phensley/[email protected]/packs/';
return new Promise(function(resolve, reject) {
fetch(`${baseurl}${language}.json`)
.then(function(r) {
return resolve(r.json());
}).catch(function(e) {
reject(e);
});
});
};
const { Decimal, DecimalConstants } = cldrengine;
const options = { asyncLoader };
const framework = new cldrengine.CLDRFramework(options);
const locales = ['en', 'de', 'fr', 'es', 'zh', 'ko', 'ja'];
const n = new Decimal('1e5').multiply(DecimalConstants.PI, { scale: 10 });
var elem = document.getElementById('out');
elem.innerHTML = 'Input: ' + n.toString() + '<br>';
for (let i = 0; i < locales.length; i++) {
const id = locales[i];
framework.getAsync(id).then(function(cldr) {
const json = {
website: {
timeZone: 'America/New_York',
},
message: 'Hello!',
now: new Date().getTime()
};
const { Compiler } = sqsptemplate2;
const compiler = new Compiler();
const source = '{message|json} {now} {now|date %c}';
let code, ctx, errors;
({ code, errors } = compiler.parse(source));
if (errors.length) {
console.log(errors.map(e => e.message).join('\n'));
}
({ ctx, errors } = compiler.execute({ cldr: cldr, code: code, json: json }));
if (errors.length) {
console.log(errors.map(e => e.message).join('\n'));
}
const output = ctx.render();
var elem = document.getElementById('out');
elem.innerHTML += output + '<br/>';
});
}
</script>
</body>
</html>