handlebars-i18n 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.commitlintrc.json +3 -0
- package/.github/workflows/ci.yml +36 -0
- package/.github/workflows/schedule.yml +49 -0
- package/.idea/.name +1 -0
- package/.idea/handlebars-i18n.iml +8 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/misc.xml +14 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/watcherTasks.xml +4 -0
- package/.releaserc.json +11 -0
- package/.travis.yml +15 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/dist/handlebars-i18n.js +423 -0
- package/dist/handlebars-i18n.min.js +1 -0
- package/examples/browser-example/img/germany.png +0 -0
- package/examples/browser-example/img/united_kingdom.png +0 -0
- package/examples/browser-example/index.html +238 -0
- package/examples/node-example/simple-example.js +172 -0
- package/gulpfile.js +11 -0
- package/package.json +67 -0
- package/readme.md +376 -0
- package/renovate.json +13 -0
- package/test/handlebars-i18n.test.js +569 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>handlebars-i18n Demo</title>
|
|
6
|
+
<style>
|
|
7
|
+
html, body {
|
|
8
|
+
margin: 1rem;
|
|
9
|
+
font-family: Helvetica Neue, Helvetica, Arial;
|
|
10
|
+
}
|
|
11
|
+
h3 {
|
|
12
|
+
margin-top: 2rem;
|
|
13
|
+
border-bottom: 1px solid black; }
|
|
14
|
+
h4 { margin: 1.5rem 0 .5rem 0;
|
|
15
|
+
}
|
|
16
|
+
code {
|
|
17
|
+
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
|
18
|
+
font-size: .8rem;
|
|
19
|
+
color: #fff;
|
|
20
|
+
background-color: #666666;
|
|
21
|
+
padding: 3px;
|
|
22
|
+
margin-left: 1rem;
|
|
23
|
+
}
|
|
24
|
+
p { margin-left: 1rem; }
|
|
25
|
+
img { margin: 1rem 0 .5rem 1rem; }
|
|
26
|
+
button { font-size: .8rem; }
|
|
27
|
+
button:hover { cursor: pointer; }
|
|
28
|
+
</style>
|
|
29
|
+
</head>
|
|
30
|
+
<body>
|
|
31
|
+
<h2>handlebars-i18n Demo</h2>
|
|
32
|
+
|
|
33
|
+
<div id="demo"><!-- handlebars' rendered demo content goes here --></div>
|
|
34
|
+
|
|
35
|
+
<!-- Dependencies: hanldebars, i18next, handlebars-i18n.js -->
|
|
36
|
+
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
|
|
37
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/19.3.2/i18next.js"></script>
|
|
38
|
+
<script src="../../dist/handlebars-i18n.js"></script>
|
|
39
|
+
<script>
|
|
40
|
+
|
|
41
|
+
'use strict';
|
|
42
|
+
|
|
43
|
+
// -- The translation phrases for i18next
|
|
44
|
+
i18next
|
|
45
|
+
.init({
|
|
46
|
+
resources : {
|
|
47
|
+
'en' : {
|
|
48
|
+
translation : {
|
|
49
|
+
'key0': 'Change Language to',
|
|
50
|
+
'key1': 'What is good?',
|
|
51
|
+
'key2': '{{what}} is good.',
|
|
52
|
+
'key3WithCount': '{{count}} item',
|
|
53
|
+
'key3WithCount_plural': '{{count}} items',
|
|
54
|
+
'key4': 'Selected Language is:'
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
'de' : {
|
|
58
|
+
translation: {
|
|
59
|
+
'key0': 'Sprache wechseln zu',
|
|
60
|
+
'key1': 'Was ist gut?',
|
|
61
|
+
'key2': '{{what}} ist gut.',
|
|
62
|
+
'key3WithCount': '{{count}} Gegenstand',
|
|
63
|
+
'key3WithCount_plural': '{{count}} Gegenstände',
|
|
64
|
+
'key4': 'Die ausgewählte Sprache ist:'
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
lng : 'en'
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// -- Handlebars' example data object
|
|
72
|
+
let data = {
|
|
73
|
+
sayWhat : 'handlebars-i18n',
|
|
74
|
+
holdKey3 : 'key3WithCount',
|
|
75
|
+
holdKey4 : 'key4',
|
|
76
|
+
mynumber : 33.333,
|
|
77
|
+
myMmaxDigits: 1,
|
|
78
|
+
myPrice: 12.99,
|
|
79
|
+
myDate: '2020-03-11T03:24:00'
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// -- Init and configure handlebars-i18n
|
|
83
|
+
HandlebarsI18n.init();
|
|
84
|
+
HandlebarsI18n.configure([
|
|
85
|
+
// generic configuration for all languages for number representation:
|
|
86
|
+
['all', 'NumberFormat', { minimumFractionDigits: 2 }],
|
|
87
|
+
// generic configurations per language for price representation:
|
|
88
|
+
['en', 'PriceFormat', { currency: 'USD'}],
|
|
89
|
+
['de', 'PriceFormat', { currency: 'EUR'}],
|
|
90
|
+
// generic configurations per language for date representation:
|
|
91
|
+
['en', 'DateTimeFormat', { year:'numeric', month:'long', day:'numeric', hour:'numeric', minute:'numeric'}],
|
|
92
|
+
['de', 'DateTimeFormat', { year:'numeric', month:'numeric', day:'numeric', hour:'numeric', minute:'numeric', hour12:false}],
|
|
93
|
+
// configurations per language with custom formats for date:
|
|
94
|
+
['en', 'DateTimeFormat', { year:'numeric' }, 'custom-year-only'],
|
|
95
|
+
['de', 'DateTimeFormat', { year:'numeric' }, 'custom-year-only'],
|
|
96
|
+
['en', 'DateTimeFormat', { year:'numeric', month:'numeric', day:'numeric' }, 'custom-date-short'],
|
|
97
|
+
['de', 'DateTimeFormat', { year:'numeric', month:'numeric', day:'numeric' }, 'custom-date-short'],
|
|
98
|
+
['en', 'DateTimeFormat', { hour:'numeric', minute:'numeric', second:'numeric', hour12:false}, 'custom-time'],
|
|
99
|
+
['de', 'DateTimeFormat', { hour:'numeric', minute:'numeric', second:'numeric', hour12:false}, 'custom-time']
|
|
100
|
+
]);
|
|
101
|
+
|
|
102
|
+
// -- The handlebars template to be rendered
|
|
103
|
+
let template =
|
|
104
|
+
'<button onclick="changeLang()">{{__ "key0"}} {{#if (localeIs "en")}}German {{else}}Englisch {{/if}}</button>' +
|
|
105
|
+
'<h3>Translations</h3>' +
|
|
106
|
+
|
|
107
|
+
'<h4>Simple translation, key given as string:</h4>' +
|
|
108
|
+
'<code>{{{{raw}}}} {{__ "key1"}} {{{{/raw}}}}</code>' +
|
|
109
|
+
'<p>{{__ "key1"}}</p>' +
|
|
110
|
+
|
|
111
|
+
'<h4>Translation with variable replacement:</h4>' +
|
|
112
|
+
'<code>{{{{raw}}}} {{__ "key2" what=sayWhat}} {{{{/raw}}}}</code>' +
|
|
113
|
+
'<p>{{__ "key2" what=sayWhat}}</p>' +
|
|
114
|
+
|
|
115
|
+
'<h4>Phrase with [singular] / plural:</h4>' +
|
|
116
|
+
'<code>{{{{raw}}}} {{__ "key3WithCount" count=1}} {{{{/raw}}}}</code>' +
|
|
117
|
+
'<p>{{__ "key3WithCount" count=1}}</p>' +
|
|
118
|
+
|
|
119
|
+
'<h4>Phrase with singular / [plural]:</h4>' +
|
|
120
|
+
'<code>{{{{raw}}}} {{__ "key3WithCount" count=7}} {{{{/raw}}}}</code>' +
|
|
121
|
+
'<p>{{__ "key3WithCount" count=7}}</p>' +
|
|
122
|
+
|
|
123
|
+
'<h4>Override language to use:</h4>' +
|
|
124
|
+
'<code>{{{{raw}}}} {{__ "key1" lng="de"}} {{{{/raw}}}}</code>' +
|
|
125
|
+
'<p>{{__ "key1" lng="de"}}</p>' +
|
|
126
|
+
|
|
127
|
+
'<h3>Output selected language</h3>' +
|
|
128
|
+
|
|
129
|
+
'<button onclick="changeLang()">{{__ "key0"}} {{#if (localeIs "en")}}German {{else}}Englisch {{/if}}</button>' +
|
|
130
|
+
|
|
131
|
+
'<h4>Translation key given through handlebars variable and _locale output:</h4>' +
|
|
132
|
+
'<code>{{{{raw}}}} {{__ holdKey4}} {{_locale}} {{{{/raw}}}}</code>' +
|
|
133
|
+
'<p>{{__ holdKey4}} {{_locale}}</p>' +
|
|
134
|
+
|
|
135
|
+
'<h4>Check against selected language:</h4>' +
|
|
136
|
+
'<code>{{{{raw}}}} <img src="img/{{#if (localeIs \'en\')}}united_kingdom{{else}}germany{{/if}}.png"/> {{{{/raw}}}}</code><br/>' +
|
|
137
|
+
'<img src="img/{{#if (localeIs \'en\')}}united_kingdom{{else}}germany{{/if}}.png" height="20"/>' +
|
|
138
|
+
|
|
139
|
+
'<h3>Number representation</h3>' +
|
|
140
|
+
|
|
141
|
+
'<button onclick="changeLang()">{{__ "key0"}} {{#if (localeIs "en")}}German {{else}}Englisch {{/if}}</button>' +
|
|
142
|
+
|
|
143
|
+
'<h4>Number representation as configured for all languages:</h4>' +
|
|
144
|
+
'<code>{{{{raw}}}} {{_num 7000}} {{{{/raw}}}}</code>' +
|
|
145
|
+
'<p>{{_num 7000}}</p>' +
|
|
146
|
+
|
|
147
|
+
'<h4>Number representation with specific format attribute:</h4>' +
|
|
148
|
+
'<code>{{{{raw}}}} {{_num 3.1415926 maximumFractionDigits=0}} {{{{/raw}}}}</code>' +
|
|
149
|
+
'<p>{{_num 3.1415926 maximumFractionDigits=0}}</p>' +
|
|
150
|
+
|
|
151
|
+
'<h4>Number and attribute given through handlebars variables:</h4>' +
|
|
152
|
+
'<code>{{{{raw}}}} {{_num mynumber maximumFractionDigits=myMaxDigits}} {{{{/raw}}}}</code>' +
|
|
153
|
+
'<p>{{_num mynumber maximumFractionDigits=myMaxDigits}}</p>' +
|
|
154
|
+
|
|
155
|
+
'<h3>Price representation</h3>' +
|
|
156
|
+
|
|
157
|
+
'<button onclick="changeLang()">{{__ "key0"}} {{#if (localeIs "en")}}German {{else}}Englisch {{/if}}</button>' +
|
|
158
|
+
|
|
159
|
+
'<h4>Price representation as configured per language:</h4>' +
|
|
160
|
+
'<code>{{{{raw}}}} {{_price 9999.99}} {{{{/raw}}}}</code>' +
|
|
161
|
+
'<p>{{_price 9999.99}}</p>' +
|
|
162
|
+
|
|
163
|
+
'<h4>Price representation with specific format attributes:</h4>' +
|
|
164
|
+
'<code>{{{{raw}}}} {{_price 1000.99 currency="JPY" minimumFractionDigits=0}} {{{{/raw}}}}</code>' +
|
|
165
|
+
'<p>{{_price 1000.99 currency="JPY" minimumFractionDigits=0}}</p>' +
|
|
166
|
+
|
|
167
|
+
'<h4>Price given through handlebars variable and with with specific format attribute:</h4>' +
|
|
168
|
+
'<code>{{{{raw}}}} {{_price myPrice currency="DKK"}} {{{{/raw}}}}</code>' +
|
|
169
|
+
'<p>{{_price myPrice currency="DKK"}}</p>' +
|
|
170
|
+
|
|
171
|
+
'<h3>Date representation</h3>' +
|
|
172
|
+
|
|
173
|
+
'<button onclick="changeLang()">{{__ "key0"}} {{#if (localeIs "en")}}German {{else}}Englisch {{/if}}</button>' +
|
|
174
|
+
|
|
175
|
+
'<h4>Todays date as configured per language:</h4>' +
|
|
176
|
+
'<code>{{{{raw}}}} {{_date}} {{{{/raw}}}}</code>' +
|
|
177
|
+
'<p>{{_date}}</p>' +
|
|
178
|
+
|
|
179
|
+
'<h4>Date given as date string:</h4>' +
|
|
180
|
+
'<code>{{{{raw}}}} {{_date "2020-03-11T03:24:00"}} {{{{/raw}}}}</code>' +
|
|
181
|
+
'<p>{{_date "2020-03-11T03:24:00"}}</p>' +
|
|
182
|
+
|
|
183
|
+
'<h4>Date given in milliseconds since begin of unix epoch:</h4>' +
|
|
184
|
+
'<code>{{{{raw}}}} {{_date 1583922952743}} {{{{/raw}}}}</code>' +
|
|
185
|
+
'<p>{{_date 1583922952743}}</p>' +
|
|
186
|
+
|
|
187
|
+
'<h4>Date given as javascript date parameter array:</h4>' +
|
|
188
|
+
'<code>{{{{raw}}}} {{_date "[2012, 11, 20, 3, 0, 0]"}} {{{{/raw}}}}</code>' +
|
|
189
|
+
'<p>{{_date "[2012, 11, 20, 3, 0, 0]"}}</p>' +
|
|
190
|
+
|
|
191
|
+
'<h4>Todays date with with specific format attributes:</h4>' +
|
|
192
|
+
'<code>{{{{raw}}}} {{_date "today" year="2-digit" month="2-digit" day="2-digit"}} {{{{/raw}}}}</code>' +
|
|
193
|
+
'<p>{{_date "today" year="2-digit" month="2-digit" day="2-digit"}}</p>' +
|
|
194
|
+
|
|
195
|
+
'<h4>Date given through handlebars variable:</h4>' +
|
|
196
|
+
'<code>{{{{raw}}}} {{_date myDate}} {{{{/raw}}}}</code>' +
|
|
197
|
+
'<p>{{_date myDate}}</p>' +
|
|
198
|
+
|
|
199
|
+
'<h4>Date formated by custom configuration (subset "custom-year-only"):</h4>' +
|
|
200
|
+
'<code>{{{{raw}}}} {{_date myDate format="custom-year-only"}} {{{{/raw}}}}</code>' +
|
|
201
|
+
'<p>{{_date myDate format="custom-year-only"}}</p>' +
|
|
202
|
+
|
|
203
|
+
'<h4>Date formated by custom configuration (subset "custom-date-short"):</h4>' +
|
|
204
|
+
'<code>{{{{raw}}}} {{_date myDate format="custom-date-short"}} {{{{/raw}}}}</code>' +
|
|
205
|
+
'<p>{{_date myDate format="custom-date-short"}}</p>' +
|
|
206
|
+
|
|
207
|
+
'<h4>Date formated by custom configuration (subset "custom-time"):</h4>' +
|
|
208
|
+
'<code>{{{{raw}}}} {{_date myDate format="custom-time"}} {{{{/raw}}}}</code>' +
|
|
209
|
+
'<p>{{_date myDate format="custom-time"}}</p>' +
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
'<p> </p><button onclick="changeLang()">{{__ "key0"}} {{#if (localeIs "en")}}German {{else}}Englisch {{/if}}</button>';
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
// -- Ignore this. It is just a helper to display un-rendered {{code}} between the <code> Tags
|
|
216
|
+
Handlebars.registerHelper('raw', function(options) {
|
|
217
|
+
return options.fn();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// -- Compile template and output to demo container
|
|
221
|
+
function compile() {
|
|
222
|
+
let compiled = Handlebars.compile(template);
|
|
223
|
+
document.getElementById('demo').innerHTML = compiled(data);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// -- Switch language function (Button)
|
|
227
|
+
function changeLang() {
|
|
228
|
+
var changeTo = i18next.language == 'en' ? 'de' : 'en';
|
|
229
|
+
i18next.changeLanguage(changeTo).then(function() {
|
|
230
|
+
compile();
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
compile();
|
|
235
|
+
|
|
236
|
+
</script>
|
|
237
|
+
</body>
|
|
238
|
+
</html>
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple example using handlebars-i18n.js
|
|
3
|
+
*
|
|
4
|
+
* @author: Florian Walzel
|
|
5
|
+
* @date: 2021-01
|
|
6
|
+
*
|
|
7
|
+
* usage:
|
|
8
|
+
* $ cd examples/node-example
|
|
9
|
+
* $ node simple-example
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const Handlebars = require('handlebars');
|
|
16
|
+
const i18next = require('i18next');
|
|
17
|
+
const HandlebarsI18n = require('../../dist/handlebars-i18n.js');
|
|
18
|
+
|
|
19
|
+
// -- The translation phrases for i18next
|
|
20
|
+
i18next
|
|
21
|
+
.init({
|
|
22
|
+
resources : {
|
|
23
|
+
'en' : {
|
|
24
|
+
translation : {
|
|
25
|
+
'key0': 'Change Language to',
|
|
26
|
+
'key1': 'What is good?',
|
|
27
|
+
'key2': '{{what}} is good.',
|
|
28
|
+
'key3WithCount': '{{count}} item',
|
|
29
|
+
'key3WithCount_plural': '{{count}} items',
|
|
30
|
+
'key4': 'Selected Language is:'
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
'de' : {
|
|
34
|
+
translation: {
|
|
35
|
+
'key0': 'Sprache wechseln zu',
|
|
36
|
+
'key1': 'Was ist gut?',
|
|
37
|
+
'key2': '{{what}} ist gut.',
|
|
38
|
+
'key3WithCount': '{{count}} Gegenstand',
|
|
39
|
+
'key3WithCount_plural': '{{count}} Gegenstände',
|
|
40
|
+
'key4': 'Die ausgewählte Sprache ist:'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
lng : 'en'
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// -- Handlebars' example data object
|
|
48
|
+
let data = {
|
|
49
|
+
sayWhat : 'handlebars-i18n',
|
|
50
|
+
holdKey3 : 'key3WithCount',
|
|
51
|
+
holdKey4 : 'key4',
|
|
52
|
+
mynumber : 33.333,
|
|
53
|
+
myMmaxDigits: 1,
|
|
54
|
+
myPrice: 12.99,
|
|
55
|
+
myDate: '2020-03-11T03:24:00'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// -- Init and configure handlebars-i18n
|
|
59
|
+
HandlebarsI18n.init();
|
|
60
|
+
HandlebarsI18n.configure([
|
|
61
|
+
// generic configuration for all languages for number representation:
|
|
62
|
+
['all', 'NumberFormat', { minimumFractionDigits: 2 }],
|
|
63
|
+
// generic configurations per language for price representation:
|
|
64
|
+
['en', 'PriceFormat', { currency: 'USD'}],
|
|
65
|
+
['de', 'PriceFormat', { currency: 'EUR'}],
|
|
66
|
+
// generic configurations per language for date representation:
|
|
67
|
+
['en', 'DateTimeFormat', { year:'numeric', month:'long', day:'numeric', hour:'numeric', minute:'numeric'}],
|
|
68
|
+
['de', 'DateTimeFormat', { year:'numeric', month:'numeric', day:'numeric', hour:'numeric', minute:'numeric', hour12:false}],
|
|
69
|
+
// configurations per language with custom formats for date:
|
|
70
|
+
['en', 'DateTimeFormat', { year:'numeric' }, 'custom-year-only'],
|
|
71
|
+
['de', 'DateTimeFormat', { year:'numeric' }, 'custom-year-only'],
|
|
72
|
+
['en', 'DateTimeFormat', { year:'numeric', month:'numeric', day:'numeric' }, 'custom-date-short'],
|
|
73
|
+
['de', 'DateTimeFormat', { year:'numeric', month:'numeric', day:'numeric' }, 'custom-date-short'],
|
|
74
|
+
['en', 'DateTimeFormat', { hour:'numeric', minute:'numeric', second:'numeric', hour12:false}, 'custom-time'],
|
|
75
|
+
['de', 'DateTimeFormat', { hour:'numeric', minute:'numeric', second:'numeric', hour12:false}, 'custom-time']
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
let template;
|
|
79
|
+
|
|
80
|
+
template = '\n' + 'EXAMPLE OUTPUT:' + '\n';
|
|
81
|
+
template += '------------------------' + '\n';
|
|
82
|
+
|
|
83
|
+
// Translations
|
|
84
|
+
// ----------------------------------------
|
|
85
|
+
|
|
86
|
+
// Simple translation, key given as string:
|
|
87
|
+
template += '{{__ "key1"}}' + '\n';
|
|
88
|
+
|
|
89
|
+
// Translation with variable replacement:
|
|
90
|
+
template += '{{__ "key2" what=sayWhat}}' + '\n';
|
|
91
|
+
|
|
92
|
+
// Phrase with [singular] / plural:
|
|
93
|
+
template += '{{__ "key3WithCount" count=1}}' + '\n';
|
|
94
|
+
|
|
95
|
+
// Phrase with singular / [plural]:
|
|
96
|
+
template += '{{__ "key3WithCount" count=7}}' + '\n';
|
|
97
|
+
|
|
98
|
+
// Override language to use:
|
|
99
|
+
template += '{{__ "key1" lng="de"}}' + '\n';
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
// Output selected language
|
|
103
|
+
// ----------------------------------------
|
|
104
|
+
|
|
105
|
+
// Translation key given through handlebars variable and _locale output:
|
|
106
|
+
template += '{{__ holdKey4}} {{_locale}}' + '\n';
|
|
107
|
+
|
|
108
|
+
// Check against selected language:
|
|
109
|
+
template += '{{#if (localeIs "en")}}English {{else}}Deutsch {{/if}}' + '\n';
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
// Number representation
|
|
113
|
+
// ----------------------------------------
|
|
114
|
+
|
|
115
|
+
// Number representation as configured for all languages:
|
|
116
|
+
template += '{{_num 7000}}' + '\n';
|
|
117
|
+
|
|
118
|
+
// Number representation with specific format attribute:
|
|
119
|
+
template += '{{_num 3.1415926 maximumFractionDigits=0}}' + '\n';
|
|
120
|
+
|
|
121
|
+
// Number and attribute given through handlebars variables:
|
|
122
|
+
template += '{{_num mynumber maximumFractionDigits=myMaxDigits}}' + '\n';
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
// Price representation
|
|
126
|
+
// ----------------------------------------
|
|
127
|
+
|
|
128
|
+
// Price representation as configured per language:
|
|
129
|
+
template += '{{_price 9999.99}}' + '\n';
|
|
130
|
+
|
|
131
|
+
// Price representation with specific format attributes:
|
|
132
|
+
template += '{{_price 1000.99 currency="JPY" minimumFractionDigits=0}}' + '\n';
|
|
133
|
+
|
|
134
|
+
// Price given through handlebars variable and with with specific format attribute:
|
|
135
|
+
template += '{{_price myPrice currency="DKK"}}' + '\n';
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
// date representation
|
|
139
|
+
// ----------------------------------------
|
|
140
|
+
|
|
141
|
+
// Todays date as configured per language:
|
|
142
|
+
template += '{{_date}}' + '\n';
|
|
143
|
+
|
|
144
|
+
// Date given as date string:
|
|
145
|
+
template += '{{_date "2020-03-11T03:24:00"}}' + '\n';
|
|
146
|
+
|
|
147
|
+
// Date given in milliseconds since begin of unix epoch:
|
|
148
|
+
template += '{{_date 1583922952743}}' + '\n';
|
|
149
|
+
|
|
150
|
+
// Date given as javascript date parameter array:
|
|
151
|
+
template += '{{_date "[2012, 11, 20, 3, 0, 0]"}}' + '\n';
|
|
152
|
+
|
|
153
|
+
// Todays date with with specific format attributes:
|
|
154
|
+
template += '{{_date "today" year="2-digit" month="2-digit" day="2-digit"}}' + '\n';
|
|
155
|
+
|
|
156
|
+
// Date given through handlebars variable:
|
|
157
|
+
template += '{{_date myDate}}' + '\n';
|
|
158
|
+
|
|
159
|
+
// Date formated by custom configuration (subset "custom-year-only"):
|
|
160
|
+
template += '{{_date myDate format="custom-year-only"}}' + '\n';
|
|
161
|
+
|
|
162
|
+
// Date formated by custom configuration (subset "custom-date-short"):
|
|
163
|
+
template += '{{_date myDate format="custom-date-short"}}' + '\n';
|
|
164
|
+
|
|
165
|
+
// Date formated by custom configuration (subset "custom-date-short"):
|
|
166
|
+
template += '{{_date myDate format="custom-time"}}' + '\n';
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
let compiled = Handlebars.compile(template);
|
|
170
|
+
i18next.changeLanguage('de'); // --> Test the changes by replacing 'de' with 'en'
|
|
171
|
+
|
|
172
|
+
console.log('\x1b[36m%s\x1b[0m', compiled(data));
|
package/gulpfile.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var gulp = require('gulp');
|
|
2
|
+
var rename = require('gulp-rename');
|
|
3
|
+
var uglify = require('gulp-uglify-es').default;
|
|
4
|
+
|
|
5
|
+
// Minifying JavaScript ES6
|
|
6
|
+
gulp.task('compress', function() {
|
|
7
|
+
return gulp.src('dist/handlebars-i18n.js')
|
|
8
|
+
.pipe(rename('handlebars-i18n.min.js'))
|
|
9
|
+
.pipe(uglify())
|
|
10
|
+
.pipe(gulp.dest('dist/'));
|
|
11
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "handlebars-i18n",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "handlebars-i18n adds internationlization to handlebars.js using i18next and Intl",
|
|
5
|
+
"main": "dist/handlebars-i18n.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "nyc mocha",
|
|
8
|
+
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
|
|
9
|
+
},
|
|
10
|
+
"directories": {
|
|
11
|
+
"test": "test"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/fwalzel/handlebars-i18n.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"handlebars-i18n",
|
|
19
|
+
"Internationalization",
|
|
20
|
+
"Localization",
|
|
21
|
+
"Globalization",
|
|
22
|
+
"Translation",
|
|
23
|
+
"Date Formatting",
|
|
24
|
+
"Currency Formatting",
|
|
25
|
+
"Number Formatting",
|
|
26
|
+
"Handlebars",
|
|
27
|
+
"Handlebars.js",
|
|
28
|
+
"i18next",
|
|
29
|
+
"i18n",
|
|
30
|
+
"Intl",
|
|
31
|
+
"Helper",
|
|
32
|
+
"handlebars-i18next"
|
|
33
|
+
],
|
|
34
|
+
"author": "Florian Walzel",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"homepage": "https://github.com/fwalzel/handlebars-i18n.git#readme",
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"handlebars": "^4.7.6",
|
|
39
|
+
"i18next": "^20.2.1",
|
|
40
|
+
"intl": "^1.2.5"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@commitlint/cli": "12.1.1",
|
|
44
|
+
"@commitlint/config-conventional": "12.1.1",
|
|
45
|
+
"chai": "4.3.4",
|
|
46
|
+
"coveralls": "3.1.0",
|
|
47
|
+
"gulp": "4.0.2",
|
|
48
|
+
"gulp-rename": "2.0.0",
|
|
49
|
+
"gulp-uglify": "3.0.2",
|
|
50
|
+
"gulp-uglify-es": "2.0.0",
|
|
51
|
+
"istanbul": "0.4.5",
|
|
52
|
+
"mocha": "8.3.2",
|
|
53
|
+
"nyc": "15.1.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"handlebars": "^4.7.6",
|
|
57
|
+
"husky": "^7.0.2",
|
|
58
|
+
"i18next": "^20.2.1",
|
|
59
|
+
"intl": "^1.2.5"
|
|
60
|
+
},
|
|
61
|
+
"husky": {
|
|
62
|
+
"hooks": {
|
|
63
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"scheduleVersion": "1.2.2"
|
|
67
|
+
}
|