handlebars-i18n 1.7.0 → 1.7.1
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/.github/workflows/coveralls.yml +44 -0
- package/dist/handlebars-i18n.d.ts +3 -3
- package/dist/handlebars-i18n.js +22 -29
- package/dist/handlebars-i18n.min.js +1 -1
- package/package.json +8 -7
- package/readme.md +3 -3
- package/test/handlebars-i18n.test.js +252 -228
|
@@ -12,7 +12,7 @@ const Handlebars = require('handlebars');
|
|
|
12
12
|
const i18next = require('i18next');
|
|
13
13
|
const HandlebarsI18n = require('../dist/handlebars-i18n');
|
|
14
14
|
|
|
15
|
-
describe('handlebars-i18n Tests', function() {
|
|
15
|
+
describe('handlebars-i18n Tests', function () {
|
|
16
16
|
|
|
17
17
|
const i18nInitObj = {
|
|
18
18
|
resources: {
|
|
@@ -99,19 +99,19 @@ describe('handlebars-i18n Tests', function() {
|
|
|
99
99
|
Tests against function _locale
|
|
100
100
|
****************************************/
|
|
101
101
|
|
|
102
|
-
it('expecting function _locale to be [undefined] as long as no language was set with i18next.init', function() {
|
|
102
|
+
it('expecting function _locale to be [undefined] as long as no language was set with i18next.init', function () {
|
|
103
103
|
i18next.init(); // empty init
|
|
104
104
|
const res = hI18n.helpers._locale();
|
|
105
105
|
expect(res).to.be.undefined;
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
it('function _locale should return "en" if language is specified as "en" by init Object', function() {
|
|
108
|
+
it('function _locale should return "en" if language is specified as "en" by init Object', function () {
|
|
109
109
|
i18next.init(i18nInitObj); // initialize with data
|
|
110
110
|
const res = hI18n.helpers._locale();
|
|
111
111
|
assert.equal('en', res);
|
|
112
112
|
});
|
|
113
113
|
|
|
114
|
-
it('function _locale should return "de" after language change to "de"', function() {
|
|
114
|
+
it('function _locale should return "de" after language change to "de"', function () {
|
|
115
115
|
i18next.changeLanguage('de');
|
|
116
116
|
const res = hI18n.helpers._locale();
|
|
117
117
|
assert.equal('de', res);
|
|
@@ -122,13 +122,13 @@ describe('handlebars-i18n Tests', function() {
|
|
|
122
122
|
Tests against function isLocale
|
|
123
123
|
****************************************/
|
|
124
124
|
|
|
125
|
-
it('function isLocale should return TRUE when current language is set to "en" and given "en" as parameter', function() {
|
|
125
|
+
it('function isLocale should return TRUE when current language is set to "en" and given "en" as parameter', function () {
|
|
126
126
|
i18next.changeLanguage('en');
|
|
127
127
|
const res = hI18n.helpers.localeIs('en');
|
|
128
128
|
assert.equal(true, res);
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
it('function isLocale should return FALSE when current language is set to "en" and given "someOther" as parameter', function() {
|
|
131
|
+
it('function isLocale should return FALSE when current language is set to "en" and given "someOther" as parameter', function () {
|
|
132
132
|
i18next.changeLanguage('en');
|
|
133
133
|
const res = hI18n.helpers.localeIs('someOther');
|
|
134
134
|
assert.equal(false, res);
|
|
@@ -139,35 +139,37 @@ describe('handlebars-i18n Tests', function() {
|
|
|
139
139
|
Tests against function __
|
|
140
140
|
****************************************/
|
|
141
141
|
|
|
142
|
-
it('expect __ to throw error when called with no parameter', function() {
|
|
143
|
-
expect(function() {
|
|
142
|
+
it('expect __ to throw error when called with no parameter', function () {
|
|
143
|
+
expect(function () {
|
|
144
|
+
hI18n.helpers.__()
|
|
145
|
+
}).to.throw();
|
|
144
146
|
});
|
|
145
147
|
|
|
146
|
-
it('function __ should return a SafeString object with property "string" where "string" returns the first argument given to __', function() {
|
|
147
|
-
const res = hI18n.helpers.__("someNoneExitingKey", {
|
|
148
|
+
it('function __ should return a SafeString object with property "string" where "string" returns the first argument given to __', function () {
|
|
149
|
+
const res = hI18n.helpers.__("someNoneExitingKey", {hash: {}});
|
|
148
150
|
assert.equal("someNoneExitingKey", res.string);
|
|
149
151
|
});
|
|
150
152
|
|
|
151
|
-
it('function __ should return a SafeString object with property "string" where "string" contains "What is good?!', function() {
|
|
152
|
-
const res = hI18n.helpers.__("key1", {
|
|
153
|
+
it('function __ should return a SafeString object with property "string" where "string" contains "What is good?!', function () {
|
|
154
|
+
const res = hI18n.helpers.__("key1", {hash: {}});
|
|
153
155
|
assert.equal("What is good?", res.string);
|
|
154
156
|
});
|
|
155
157
|
|
|
156
|
-
it('function __ should return a SafeString object with property "string" where "string" contains "Was ist gut?"', function() {
|
|
158
|
+
it('function __ should return a SafeString object with property "string" where "string" contains "Was ist gut?"', function () {
|
|
157
159
|
i18next.changeLanguage('de');
|
|
158
|
-
const res = hI18n.helpers.__("key1", {
|
|
160
|
+
const res = hI18n.helpers.__("key1", {hash: {}});
|
|
159
161
|
assert.equal("Was ist gut?", res.string);
|
|
160
162
|
});
|
|
161
163
|
|
|
162
|
-
it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next is good."', function() {
|
|
164
|
+
it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next is good."', function () {
|
|
163
165
|
i18next.changeLanguage('en');
|
|
164
|
-
const res = hI18n.helpers.__("key2", {
|
|
166
|
+
const res = hI18n.helpers.__("key2", {hash: {what: "handlebarsI18next", adverb: "good"}});
|
|
165
167
|
assert.equal("handlebarsI18next is good.", res.string);
|
|
166
168
|
});
|
|
167
169
|
|
|
168
|
-
it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next ist gut."', function() {
|
|
170
|
+
it('function __ should return a SafeString object with property "string" where "string" contains "handlebarsI18next ist gut."', function () {
|
|
169
171
|
i18next.changeLanguage('de');
|
|
170
|
-
const res = hI18n.helpers.__("key2", {
|
|
172
|
+
const res = hI18n.helpers.__("key2", {hash: {what: "handlebarsI18next", adverb: "gut"}});
|
|
171
173
|
assert.equal("handlebarsI18next ist gut.", res.string);
|
|
172
174
|
});
|
|
173
175
|
|
|
@@ -176,11 +178,13 @@ describe('handlebars-i18n Tests', function() {
|
|
|
176
178
|
Tests against function _date
|
|
177
179
|
****************************************/
|
|
178
180
|
|
|
179
|
-
it('expect function _date to throw error when called with invalid date parameter', function() {
|
|
180
|
-
expect(function() {
|
|
181
|
+
it('expect function _date to throw error when called with invalid date parameter', function () {
|
|
182
|
+
expect(function () {
|
|
183
|
+
hI18n.helpers._date('someStrangeString')
|
|
184
|
+
}).to.throw("Invalid valid date passed to format");
|
|
181
185
|
});
|
|
182
186
|
|
|
183
|
-
it('function _date should return today’s date in Intl default format when called without parameter', function() {
|
|
187
|
+
it('function _date should return today’s date in Intl default format when called without parameter', function () {
|
|
184
188
|
i18next.changeLanguage('en');
|
|
185
189
|
const today = new Date();
|
|
186
190
|
const todayFormated = new Intl.DateTimeFormat().format(today);
|
|
@@ -190,7 +194,7 @@ describe('handlebars-i18n Tests', function() {
|
|
|
190
194
|
});
|
|
191
195
|
|
|
192
196
|
it('function _date should return today’s date in Intl default format when called with parameter, "Today" or "Now" no matter of upper or lower case writing',
|
|
193
|
-
function() {
|
|
197
|
+
function () {
|
|
194
198
|
i18next.changeLanguage('en');
|
|
195
199
|
const today = new Date();
|
|
196
200
|
const todayFormated = new Intl.DateTimeFormat().format(today);
|
|
@@ -201,53 +205,53 @@ describe('handlebars-i18n Tests', function() {
|
|
|
201
205
|
assert.equal(todayFormated, hI18n.helpers._date("now"));
|
|
202
206
|
assert.equal(todayFormated, hI18n.helpers._date("Now"));
|
|
203
207
|
assert.equal(todayFormated, hI18n.helpers._date("NOW"));
|
|
204
|
-
|
|
208
|
+
});
|
|
205
209
|
|
|
206
|
-
it('function _date should return "1/1/1970" (Intl default format) when called with parameter 1 as number ', function() {
|
|
210
|
+
it('function _date should return "1/1/1970" (Intl default format) when called with parameter 1 as number ', function () {
|
|
207
211
|
i18next.changeLanguage('en');
|
|
208
212
|
const res = hI18n.helpers._date(1);
|
|
209
213
|
assert.equal('1/1/1970', res);
|
|
210
214
|
});
|
|
211
215
|
|
|
212
|
-
it('function _date should return "12/17/1995" (Intl default format) when called with parameter "1995-12-17T03:24:00"', function() {
|
|
216
|
+
it('function _date should return "12/17/1995" (Intl default format) when called with parameter "1995-12-17T03:24:00"', function () {
|
|
213
217
|
i18next.changeLanguage('en');
|
|
214
218
|
const res = hI18n.helpers._date('1995-12-17T03:24:00');
|
|
215
219
|
assert.equal('12/17/1995', res);
|
|
216
220
|
});
|
|
217
221
|
|
|
218
|
-
it('function _date should return "12/17/1995" (Intl default format) when called with parameter "December 17, 1995 03:24:00"', function() {
|
|
222
|
+
it('function _date should return "12/17/1995" (Intl default format) when called with parameter "December 17, 1995 03:24:00"', function () {
|
|
219
223
|
i18next.changeLanguage('en');
|
|
220
224
|
const res = hI18n.helpers._date('December 17, 1995 03:24:00');
|
|
221
225
|
assert.equal('12/17/1995', res);
|
|
222
226
|
});
|
|
223
227
|
|
|
224
|
-
it('function _date should return "1/1/2020" (Intl default format) when called with parameter "[2020]"', function() {
|
|
228
|
+
it('function _date should return "1/1/2020" (Intl default format) when called with parameter "[2020]"', function () {
|
|
225
229
|
i18next.changeLanguage('en');
|
|
226
230
|
const res = hI18n.helpers._date('[1995]');
|
|
227
231
|
assert.equal('1/1/1995', res);
|
|
228
232
|
});
|
|
229
233
|
|
|
230
|
-
it('function _date should return "12/1/1995" (Intl default format) when called with parameter "[2020,11]"', function() {
|
|
234
|
+
it('function _date should return "12/1/1995" (Intl default format) when called with parameter "[2020,11]"', function () {
|
|
231
235
|
i18next.changeLanguage('en');
|
|
232
236
|
const res = hI18n.helpers._date('[1995,11]');
|
|
233
237
|
assert.equal('12/1/1995', res);
|
|
234
238
|
});
|
|
235
239
|
|
|
236
|
-
it('function _date should return "12/17/1995" (Intl default format) when called with parameter "[2020,11,17]"', function() {
|
|
240
|
+
it('function _date should return "12/17/1995" (Intl default format) when called with parameter "[2020,11,17]"', function () {
|
|
237
241
|
i18next.changeLanguage('en');
|
|
238
242
|
const res = hI18n.helpers._date('[1995,11,17]');
|
|
239
243
|
assert.equal('12/17/1995', res);
|
|
240
244
|
});
|
|
241
245
|
|
|
242
|
-
it('function _date should return "12/1/95" when called with parameter "[2020,11,01] and specifying options"', function() {
|
|
246
|
+
it('function _date should return "12/1/95" when called with parameter "[2020,11,01] and specifying options"', function () {
|
|
243
247
|
i18next.changeLanguage('en');
|
|
244
|
-
const res = hI18n.helpers._date('[1995,11,1]', {
|
|
248
|
+
const res = hI18n.helpers._date('[1995,11,1]', {hash: {year: "2-digit", month: "2-digit", day: "2-digit"}});
|
|
245
249
|
assert.equal('12/1/95', res);
|
|
246
250
|
});
|
|
247
251
|
|
|
248
|
-
it('function _date should return "01.12.95" when called with parameter "[2020,11,01] and specifying options an language set to "de"', function() {
|
|
252
|
+
it('function _date should return "01.12.95" when called with parameter "[2020,11,01] and specifying options an language set to "de"', function () {
|
|
249
253
|
i18next.changeLanguage('de');
|
|
250
|
-
const res = hI18n.helpers._date('[1995,11,1]', {
|
|
254
|
+
const res = hI18n.helpers._date('[1995,11,1]', {hash: {year: "2-digit", month: "2-digit", day: "2-digit"}});
|
|
251
255
|
assert.equal('01.12.95', res);
|
|
252
256
|
});
|
|
253
257
|
|
|
@@ -256,42 +260,60 @@ describe('handlebars-i18n Tests', function() {
|
|
|
256
260
|
Tests against function _dateRel
|
|
257
261
|
****************************************/
|
|
258
262
|
|
|
259
|
-
it('expect function _dateRel to throw error when called without parameter', function() {
|
|
260
|
-
expect(function() {
|
|
263
|
+
it('expect function _dateRel to throw error when called without parameter', function () {
|
|
264
|
+
expect(function () {
|
|
265
|
+
hI18n.helpers._dateRel()
|
|
266
|
+
}).to.throw('Invalid "number" argument: NaN');
|
|
261
267
|
});
|
|
262
268
|
|
|
263
|
-
it('expect function _dateRel to throw error when called with invalid date parameter', function() {
|
|
264
|
-
expect(function() {
|
|
269
|
+
it('expect function _dateRel to throw error when called with invalid date parameter', function () {
|
|
270
|
+
expect(function () {
|
|
271
|
+
hI18n.helpers._dateRel('someStrangeString')
|
|
272
|
+
}).to.throw('Invalid "number" argument: NaN');
|
|
265
273
|
});
|
|
266
274
|
|
|
267
|
-
it('expect function _dateRel to throw error when called with non-existent language shortcode', function() {
|
|
275
|
+
it('expect function _dateRel to throw error when called with non-existent language shortcode', function () {
|
|
268
276
|
i18next.changeLanguage('invalid');
|
|
269
|
-
expect(function() {
|
|
270
|
-
hI18n.helpers._dateRel(1, {
|
|
277
|
+
expect(function () {
|
|
278
|
+
hI18n.helpers._dateRel(1, {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: "day"}})
|
|
271
279
|
}).to.throw('No locale data passed');
|
|
272
280
|
});
|
|
273
281
|
|
|
274
|
-
it('expect function _dateRel to return \'in 1 hour\' when called with \'en\' and first parameter being 1', function() {
|
|
282
|
+
it('expect function _dateRel to return \'in 1 hour\' when called with \'en\' and first parameter being 1', function () {
|
|
275
283
|
i18next.changeLanguage('en');
|
|
276
284
|
const res = hI18n.helpers._dateRel(1);
|
|
277
285
|
assert.equal('in 1 hour', res);
|
|
278
286
|
});
|
|
279
287
|
|
|
280
|
-
it('expect function _dateRel to return \'1 hour ago\' when called with \'en\' and first parameter being -1', function() {
|
|
288
|
+
it('expect function _dateRel to return \'1 hour ago\' when called with \'en\' and first parameter being -1', function () {
|
|
281
289
|
i18next.changeLanguage('en');
|
|
282
290
|
const res = hI18n.helpers._dateRel(-1);
|
|
283
291
|
assert.equal('1 hour ago', res);
|
|
284
292
|
});
|
|
285
293
|
|
|
286
|
-
it('expect function _dateRel to return \'in 1 second\' when called with \'en\' and first parameter being 1 and according options', function() {
|
|
294
|
+
it('expect function _dateRel to return \'in 1 second\' when called with \'en\' and first parameter being 1 and according options', function () {
|
|
287
295
|
i18next.changeLanguage('en');
|
|
288
|
-
const res = hI18n.helpers._dateRel(1, {
|
|
296
|
+
const res = hI18n.helpers._dateRel(1, {
|
|
297
|
+
hash: {
|
|
298
|
+
localeMatcher: "best fit",
|
|
299
|
+
numeric: "always",
|
|
300
|
+
style: "long",
|
|
301
|
+
unit: "seconds"
|
|
302
|
+
}
|
|
303
|
+
});
|
|
289
304
|
assert.equal('in 1 second', res);
|
|
290
305
|
});
|
|
291
306
|
|
|
292
|
-
it('expect function _dateRel to return \'in 1 Tag\' when called with \'de\' and paramter 1 and according options', function() {
|
|
307
|
+
it('expect function _dateRel to return \'in 1 Tag\' when called with \'de\' and paramter 1 and according options', function () {
|
|
293
308
|
i18next.changeLanguage('de');
|
|
294
|
-
const res = hI18n.helpers._dateRel(1, {
|
|
309
|
+
const res = hI18n.helpers._dateRel(1, {
|
|
310
|
+
hash: {
|
|
311
|
+
localeMatcher: "best fit",
|
|
312
|
+
numeric: "always",
|
|
313
|
+
style: "long",
|
|
314
|
+
unit: "day"
|
|
315
|
+
}
|
|
316
|
+
});
|
|
295
317
|
assert.equal('in 1 Tag', res);
|
|
296
318
|
});
|
|
297
319
|
|
|
@@ -300,35 +322,33 @@ describe('handlebars-i18n Tests', function() {
|
|
|
300
322
|
Tests against function _dateDiff
|
|
301
323
|
****************************************/
|
|
302
324
|
|
|
303
|
-
it('function _dateDiff should return null when called with no parameter', function() {
|
|
325
|
+
it('function _dateDiff should return null when called with no parameter', function () {
|
|
304
326
|
i18next.changeLanguage('en');
|
|
305
327
|
const res = hI18n.helpers._dateDiff();
|
|
306
328
|
assert.equal(null, res);
|
|
307
329
|
});
|
|
308
330
|
|
|
309
|
-
it('expect function _dateDiff to throw error when called with invalid 1. date parameter', function() {
|
|
310
|
-
expect(function() {
|
|
331
|
+
it('expect function _dateDiff to throw error when called with invalid 1. date parameter', function () {
|
|
332
|
+
expect(function () {
|
|
333
|
+
hI18n.helpers._dateDiff('someStrangeString', '1995-12-17T03:24:00')
|
|
334
|
+
})
|
|
311
335
|
.to.throw('Invalid "number" argument: NaN');
|
|
312
336
|
});
|
|
313
337
|
|
|
314
|
-
it('expect function _dateDiff to throw error when called with invalid 2. date parameter', function() {
|
|
315
|
-
expect(function() {
|
|
338
|
+
it('expect function _dateDiff to throw error when called with invalid 2. date parameter', function () {
|
|
339
|
+
expect(function () {
|
|
340
|
+
hI18n.helpers._dateDiff('1995-12-17T03:24:00', 'someStrangeString')
|
|
341
|
+
})
|
|
316
342
|
.to.throw('Invalid "number" argument: NaN');
|
|
317
343
|
});
|
|
318
344
|
|
|
319
|
-
|
|
345
|
+
it('expect function _dateDiff to return null when called with empty argument', function () {
|
|
320
346
|
i18next.changeLanguage('en');
|
|
321
|
-
const res = hI18n.helpers._dateDiff('
|
|
322
|
-
assert.equal(
|
|
323
|
-
});*/
|
|
324
|
-
|
|
325
|
-
it('expect function _dateDiff to return the second date as "in 227,543 hours", when first param is empty', function() {
|
|
326
|
-
i18next.changeLanguage('en');
|
|
327
|
-
const res = hI18n.helpers._dateDiff('', '1995-12-17T00:00:00');
|
|
328
|
-
assert.equal('in 227,543 hours', res);
|
|
347
|
+
const res = hI18n.helpers._dateDiff('');
|
|
348
|
+
assert.equal(null, res);
|
|
329
349
|
});
|
|
330
350
|
|
|
331
|
-
it('expect function _dateDiff to return "in 0 hours", when dates are identical', function() {
|
|
351
|
+
it('expect function _dateDiff to return "in 0 hours", when dates are identical', function () {
|
|
332
352
|
i18next.changeLanguage('en');
|
|
333
353
|
const res = hI18n.helpers._dateDiff('1995-12-17T00:00:00', '1995-12-17T00:00:00');
|
|
334
354
|
assert.equal('in 0 hours', res);
|
|
@@ -336,124 +356,124 @@ describe('handlebars-i18n Tests', function() {
|
|
|
336
356
|
|
|
337
357
|
// -- Test year -- //
|
|
338
358
|
|
|
339
|
-
it('expect function _dateDiff to return "in 1 year"', function() {
|
|
359
|
+
it('expect function _dateDiff to return "in 1 year"', function () {
|
|
340
360
|
i18next.changeLanguage('en');
|
|
341
|
-
const hash = {
|
|
361
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: "year"}};
|
|
342
362
|
const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1995-12-17T00:00:00', hash);
|
|
343
363
|
assert.equal('in 1 year', res);
|
|
344
364
|
});
|
|
345
365
|
|
|
346
|
-
it('expect function _dateDiff to return "1 year ago"', function() {
|
|
366
|
+
it('expect function _dateDiff to return "1 year ago"', function () {
|
|
347
367
|
i18next.changeLanguage('en');
|
|
348
|
-
const hash = {
|
|
368
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: "year"}};
|
|
349
369
|
const res = hI18n.helpers._dateDiff('1995-12-17T00:00:00', '1996-12-17T00:00:00', hash);
|
|
350
370
|
assert.equal('1 year ago', res);
|
|
351
371
|
});
|
|
352
372
|
|
|
353
373
|
// -- Test quarter -- //
|
|
354
374
|
|
|
355
|
-
it('expect function _dateDiff to return "in 1 quarter"', function() {
|
|
375
|
+
it('expect function _dateDiff to return "in 1 quarter"', function () {
|
|
356
376
|
i18next.changeLanguage('en');
|
|
357
377
|
const unit = 'quarter';
|
|
358
|
-
const hash = {
|
|
378
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
359
379
|
const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1996-09-16T00:00:00', hash);
|
|
360
380
|
assert.equal(`in 1 ${unit}`, res);
|
|
361
381
|
});
|
|
362
382
|
|
|
363
|
-
it('expect function _dateDiff to return "1 quarter ago"', function() {
|
|
383
|
+
it('expect function _dateDiff to return "1 quarter ago"', function () {
|
|
364
384
|
i18next.changeLanguage('en');
|
|
365
385
|
const unit = 'quarter';
|
|
366
|
-
const hash = {
|
|
386
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
367
387
|
const res = hI18n.helpers._dateDiff('1996-09-16T00:00:00', '1996-12-17T00:00:00', hash);
|
|
368
388
|
assert.equal(`1 ${unit} ago`, res);
|
|
369
389
|
});
|
|
370
390
|
|
|
371
391
|
// -- Test month -- //
|
|
372
392
|
|
|
373
|
-
it('expect function _dateDiff to return "in 1 month"', function() {
|
|
393
|
+
it('expect function _dateDiff to return "in 1 month"', function () {
|
|
374
394
|
i18next.changeLanguage('en');
|
|
375
395
|
const unit = 'month';
|
|
376
|
-
const hash = {
|
|
396
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
377
397
|
const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1996-11-16T00:00:00', hash);
|
|
378
398
|
assert.equal(`in 1 ${unit}`, res);
|
|
379
399
|
});
|
|
380
400
|
|
|
381
|
-
it('expect function _dateDiff to return "1 month ago"', function() {
|
|
401
|
+
it('expect function _dateDiff to return "1 month ago"', function () {
|
|
382
402
|
i18next.changeLanguage('en');
|
|
383
403
|
const unit = 'month';
|
|
384
|
-
const hash = {
|
|
404
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
385
405
|
const res = hI18n.helpers._dateDiff('1996-11-16T00:00:00', '1996-12-17T00:00:00', hash);
|
|
386
406
|
assert.equal(`1 ${unit} ago`, res);
|
|
387
407
|
});
|
|
388
408
|
|
|
389
409
|
// -- Test week -- //
|
|
390
410
|
|
|
391
|
-
it('expect function _dateDiff to return "in 1 week"', function() {
|
|
411
|
+
it('expect function _dateDiff to return "in 1 week"', function () {
|
|
392
412
|
i18next.changeLanguage('en');
|
|
393
413
|
const unit = 'week';
|
|
394
|
-
const hash = {
|
|
414
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
395
415
|
const res = hI18n.helpers._dateDiff('1996-12-08T00:00:00', '1996-12-01T00:00:00', hash);
|
|
396
416
|
assert.equal(`in 1 ${unit}`, res);
|
|
397
417
|
});
|
|
398
418
|
|
|
399
|
-
it('expect function _dateDiff to return "1 week ago"', function() {
|
|
419
|
+
it('expect function _dateDiff to return "1 week ago"', function () {
|
|
400
420
|
i18next.changeLanguage('en');
|
|
401
421
|
const unit = 'week';
|
|
402
|
-
const hash = {
|
|
422
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
403
423
|
const res = hI18n.helpers._dateDiff('1996-12-01T00:00:00', '1996-12-08T00:00:00', hash);
|
|
404
424
|
assert.equal(`1 ${unit} ago`, res);
|
|
405
425
|
});
|
|
406
426
|
|
|
407
427
|
// -- Test day -- //
|
|
408
428
|
|
|
409
|
-
it('expect function _dateDiff to return "in 1 day"', function() {
|
|
429
|
+
it('expect function _dateDiff to return "in 1 day"', function () {
|
|
410
430
|
i18next.changeLanguage('en');
|
|
411
431
|
const unit = 'day';
|
|
412
|
-
const hash = {
|
|
432
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
413
433
|
const res = hI18n.helpers._dateDiff('1996-12-08T00:00:00', '1996-12-07T00:00:00', hash);
|
|
414
434
|
assert.equal(`in 1 ${unit}`, res);
|
|
415
435
|
});
|
|
416
436
|
|
|
417
|
-
it('expect function _dateDiff to return "1 day ago"', function() {
|
|
437
|
+
it('expect function _dateDiff to return "1 day ago"', function () {
|
|
418
438
|
i18next.changeLanguage('en');
|
|
419
439
|
const unit = 'day';
|
|
420
|
-
const hash = {
|
|
440
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
421
441
|
const res = hI18n.helpers._dateDiff('1996-12-07T00:00:00', '1996-12-08T00:00:00', hash);
|
|
422
442
|
assert.equal(`1 ${unit} ago`, res);
|
|
423
443
|
});
|
|
424
444
|
|
|
425
445
|
// -- Test minute -- //
|
|
426
446
|
|
|
427
|
-
it('expect function _dateDiff to return "in 1 minute"', function() {
|
|
447
|
+
it('expect function _dateDiff to return "in 1 minute"', function () {
|
|
428
448
|
i18next.changeLanguage('en');
|
|
429
449
|
const unit = 'minute';
|
|
430
|
-
const hash = {
|
|
450
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
431
451
|
const res = hI18n.helpers._dateDiff('1996-12-08T00:01:00', '1996-12-08T00:00:00', hash);
|
|
432
452
|
assert.equal(`in 1 ${unit}`, res);
|
|
433
453
|
});
|
|
434
454
|
|
|
435
|
-
it('expect function _dateDiff to return "1 minute ago"', function() {
|
|
455
|
+
it('expect function _dateDiff to return "1 minute ago"', function () {
|
|
436
456
|
i18next.changeLanguage('en');
|
|
437
457
|
const unit = 'minute';
|
|
438
|
-
const hash = {
|
|
458
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
439
459
|
const res = hI18n.helpers._dateDiff('1996-12-08T00:00:00', '1996-12-08T00:01:00', hash);
|
|
440
460
|
assert.equal(`1 ${unit} ago`, res);
|
|
441
461
|
});
|
|
442
462
|
|
|
443
463
|
// -- Test second -- //
|
|
444
464
|
|
|
445
|
-
it('expect function _dateDiff to return "in 1 second"', function() {
|
|
465
|
+
it('expect function _dateDiff to return "in 1 second"', function () {
|
|
446
466
|
i18next.changeLanguage('en');
|
|
447
467
|
const unit = 'second';
|
|
448
|
-
const hash = {
|
|
468
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
449
469
|
const res = hI18n.helpers._dateDiff('1996-12-08T00:00:01', '1996-12-08T00:00:00', hash);
|
|
450
470
|
assert.equal(`in 1 ${unit}`, res);
|
|
451
471
|
});
|
|
452
472
|
|
|
453
|
-
it('expect function _dateDiff to return "1 second ago"', function() {
|
|
473
|
+
it('expect function _dateDiff to return "1 second ago"', function () {
|
|
454
474
|
i18next.changeLanguage('en');
|
|
455
475
|
const unit = 'second';
|
|
456
|
-
const hash = {
|
|
476
|
+
const hash = {hash: {localeMatcher: "best fit", numeric: "always", style: "long", unit: unit}};
|
|
457
477
|
const res = hI18n.helpers._dateDiff('1996-12-08T00:00:00', '1996-12-08T00:00:01', hash);
|
|
458
478
|
assert.equal(`1 ${unit} ago`, res);
|
|
459
479
|
});
|
|
@@ -463,27 +483,27 @@ describe('handlebars-i18n Tests', function() {
|
|
|
463
483
|
Tests against function _num
|
|
464
484
|
****************************************/
|
|
465
485
|
|
|
466
|
-
it('function _num should return comma separated triples of decimals when language is "en"', function() {
|
|
486
|
+
it('function _num should return comma separated triples of decimals when language is "en"', function () {
|
|
467
487
|
i18next.changeLanguage('en');
|
|
468
|
-
const res = hI18n.helpers._num(4000000, {
|
|
488
|
+
const res = hI18n.helpers._num(4000000, {hash: {}});
|
|
469
489
|
assert.equal('4,000,000', res);
|
|
470
490
|
});
|
|
471
491
|
|
|
472
|
-
it('function _num should return dot separated triples of decimals when language is "de"', function() {
|
|
492
|
+
it('function _num should return dot separated triples of decimals when language is "de"', function () {
|
|
473
493
|
i18next.changeLanguage('de');
|
|
474
|
-
const res = hI18n.helpers._num(4000000, {
|
|
494
|
+
const res = hI18n.helpers._num(4000000, {hash: {}});
|
|
475
495
|
assert.equal('4.000.000', res);
|
|
476
496
|
});
|
|
477
497
|
|
|
478
|
-
it('function _num should return comma separated triples of decimals and 2 fraction digits"', function() {
|
|
498
|
+
it('function _num should return comma separated triples of decimals and 2 fraction digits"', function () {
|
|
479
499
|
i18next.changeLanguage('en');
|
|
480
|
-
const res = hI18n.helpers._num(4000000, {
|
|
500
|
+
const res = hI18n.helpers._num(4000000, {hash: {minimumFractionDigits: 2}});
|
|
481
501
|
assert.equal('4,000,000.00', res);
|
|
482
502
|
});
|
|
483
503
|
|
|
484
|
-
it('function _num should return dot separated triples of decimals and 2 fraction digits when language is "de"', function() {
|
|
504
|
+
it('function _num should return dot separated triples of decimals and 2 fraction digits when language is "de"', function () {
|
|
485
505
|
i18next.changeLanguage('de');
|
|
486
|
-
const res = hI18n.helpers._num(4000000, {
|
|
506
|
+
const res = hI18n.helpers._num(4000000, {hash: {minimumFractionDigits: 2}});
|
|
487
507
|
assert.equal('4.000.000,00', res);
|
|
488
508
|
});
|
|
489
509
|
|
|
@@ -492,28 +512,28 @@ describe('handlebars-i18n Tests', function() {
|
|
|
492
512
|
Tests against function _price
|
|
493
513
|
****************************************/
|
|
494
514
|
|
|
495
|
-
it('function _currency should return price in € written in comma separated triples of decimals and 2 fraction digits with leading currency symbol', function() {
|
|
515
|
+
it('function _currency should return price in € written in comma separated triples of decimals and 2 fraction digits with leading currency symbol', function () {
|
|
496
516
|
i18next.changeLanguage('en');
|
|
497
|
-
const res = hI18n.helpers._price(4000000, {
|
|
517
|
+
const res = hI18n.helpers._price(4000000, {hash: {}});
|
|
498
518
|
assert.equal('€4,000,000.00', res);
|
|
499
519
|
});
|
|
500
520
|
|
|
501
|
-
it('function _currency should return price in € written in dot separated triples of decimals and 2 fraction digits with trailing currency symbol', function() {
|
|
521
|
+
it('function _currency should return price in € written in dot separated triples of decimals and 2 fraction digits with trailing currency symbol', function () {
|
|
502
522
|
i18next.changeLanguage('de');
|
|
503
|
-
const res = hI18n.helpers._price(4000000, {
|
|
523
|
+
const res = hI18n.helpers._price(4000000, {hash: {}});
|
|
504
524
|
assert.isString(res);
|
|
505
525
|
assert.equal('4.000.000,00 €', res);
|
|
506
526
|
});
|
|
507
527
|
|
|
508
|
-
it('function _currency should return price in ¥ written in comma separated triples of decimals with leading currency symbol', function() {
|
|
528
|
+
it('function _currency should return price in ¥ written in comma separated triples of decimals with leading currency symbol', function () {
|
|
509
529
|
i18next.changeLanguage('en');
|
|
510
|
-
const res = hI18n.helpers._price(4000000, {
|
|
530
|
+
const res = hI18n.helpers._price(4000000, {hash: {currency: 'JPY', maximumFractionDigits: 0}});
|
|
511
531
|
assert.equal('¥4,000,000', res);
|
|
512
532
|
});
|
|
513
533
|
|
|
514
|
-
it('function _currency should return price in ¥ written in comma separated triples of decimals with trailing currency symbol', function() {
|
|
534
|
+
it('function _currency should return price in ¥ written in comma separated triples of decimals with trailing currency symbol', function () {
|
|
515
535
|
i18next.changeLanguage('de');
|
|
516
|
-
const res = hI18n.helpers._price(4000000, {
|
|
536
|
+
const res = hI18n.helpers._price(4000000, {hash: {currency: 'JPY', maximumFractionDigits: 0}});
|
|
517
537
|
assert.equal('4.000.000 ¥', res);
|
|
518
538
|
});
|
|
519
539
|
|
|
@@ -522,53 +542,57 @@ describe('handlebars-i18n Tests', function() {
|
|
|
522
542
|
Tests against method configure()
|
|
523
543
|
****************************************/
|
|
524
544
|
|
|
525
|
-
it('method configure() should return false if called without argument', function() {
|
|
545
|
+
it('method configure() should return false if called without argument', function () {
|
|
526
546
|
const configure = HandlebarsI18n.configure();
|
|
527
547
|
assert.isNotOk(configure);
|
|
528
548
|
});
|
|
529
549
|
|
|
530
|
-
it('method configure() should return false if called with empty array []', function() {
|
|
550
|
+
it('method configure() should return false if called with empty array []', function () {
|
|
531
551
|
const configure = HandlebarsI18n.configure([]);
|
|
532
552
|
assert.isNotOk(configure);
|
|
533
553
|
});
|
|
534
554
|
|
|
535
|
-
it('method configure() should return false if called with only one argument', function() {
|
|
555
|
+
it('method configure() should return false if called with only one argument', function () {
|
|
536
556
|
const configure = HandlebarsI18n.configure('en');
|
|
537
557
|
assert.isNotOk(configure);
|
|
538
558
|
});
|
|
539
559
|
|
|
540
|
-
it('method configure() should return false if called with language argument and invalid second argument', function() {
|
|
560
|
+
it('method configure() should return false if called with language argument and invalid second argument', function () {
|
|
541
561
|
const configure = HandlebarsI18n.configure('en', 'somestrangeinput');
|
|
542
562
|
assert.isNotOk(configure);
|
|
543
563
|
});
|
|
544
564
|
|
|
545
|
-
it('method configure() should return false if called with language argument "en" and second argument "DateTimeFormat" and Number (invalid argument) as third', function() {
|
|
565
|
+
it('method configure() should return false if called with language argument "en" and second argument "DateTimeFormat" and Number (invalid argument) as third', function () {
|
|
546
566
|
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', 12);
|
|
547
567
|
assert.isNotOk(configure);
|
|
548
568
|
});
|
|
549
569
|
|
|
550
|
-
it('method configure() should return true if called with language argument "en" and second argument "DateTimeFormat" and options object as third argument', function() {
|
|
551
|
-
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {
|
|
570
|
+
it('method configure() should return true if called with language argument "en" and second argument "DateTimeFormat" and options object as third argument', function () {
|
|
571
|
+
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {year: 'numeric'});
|
|
552
572
|
assert.isOk(configure);
|
|
553
573
|
});
|
|
554
574
|
|
|
555
|
-
it('method configure() should return true if called with arguments "en", "DateTimeFormat", { year:"numeric" } and a string as custom configuration name', function() {
|
|
556
|
-
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {
|
|
575
|
+
it('method configure() should return true if called with arguments "en", "DateTimeFormat", { year:"numeric" } and a string as custom configuration name', function () {
|
|
576
|
+
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {year: 'numeric'}, "my-custom-conf");
|
|
557
577
|
assert.isOk(configure);
|
|
558
578
|
});
|
|
559
579
|
|
|
560
|
-
it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional object (invalid argument)', function() {
|
|
561
|
-
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {
|
|
580
|
+
it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional object (invalid argument)', function () {
|
|
581
|
+
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {year: 'numeric'}, {});
|
|
562
582
|
assert.isNotOk(configure);
|
|
563
583
|
});
|
|
564
584
|
|
|
565
|
-
it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional empty string (invalid argument)', function() {
|
|
566
|
-
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {
|
|
585
|
+
it('method configure() should return false if called with arguments "en", "DateTimeFormat", { year:"numeric" } and an additional empty string (invalid argument)', function () {
|
|
586
|
+
const configure = HandlebarsI18n.configure('en', 'DateTimeFormat', {year: 'numeric'}, "");
|
|
567
587
|
assert.isNotOk(configure);
|
|
568
588
|
});
|
|
569
589
|
|
|
570
|
-
it('method configure() should return true if called with arguments "en", "RelativeTimeFormat", { localeMatcher: "best fit", numeric: "always", style: "long" }', function() {
|
|
571
|
-
const configure = HandlebarsI18n.configure('en', 'RelativeTimeFormat', {
|
|
590
|
+
it('method configure() should return true if called with arguments "en", "RelativeTimeFormat", { localeMatcher: "best fit", numeric: "always", style: "long" }', function () {
|
|
591
|
+
const configure = HandlebarsI18n.configure('en', 'RelativeTimeFormat', {
|
|
592
|
+
localeMatcher: "best fit",
|
|
593
|
+
numeric: "always",
|
|
594
|
+
style: "long"
|
|
595
|
+
});
|
|
572
596
|
assert.isOk(configure);
|
|
573
597
|
});
|
|
574
598
|
|
|
@@ -577,13 +601,13 @@ describe('handlebars-i18n Tests', function() {
|
|
|
577
601
|
Tests against method reset()
|
|
578
602
|
****************************************/
|
|
579
603
|
|
|
580
|
-
it('method reset() should return TRUE if called', function() {
|
|
604
|
+
it('method reset() should return TRUE if called', function () {
|
|
581
605
|
const res = HandlebarsI18n.reset();
|
|
582
606
|
assert.isOk(res);
|
|
583
607
|
});
|
|
584
608
|
|
|
585
|
-
it('function _num should return Intl standard format (no fraction digits) after reset() being called', function() {
|
|
586
|
-
HandlebarsI18n.configure('en', 'NumberFormat', {
|
|
609
|
+
it('function _num should return Intl standard format (no fraction digits) after reset() being called', function () {
|
|
610
|
+
HandlebarsI18n.configure('en', 'NumberFormat', {minimumFractionDigits: 4});
|
|
587
611
|
i18next.changeLanguage('en');
|
|
588
612
|
HandlebarsI18n.reset();
|
|
589
613
|
const res = hI18n.helpers._num(4000000);
|
|
@@ -596,73 +620,73 @@ describe('handlebars-i18n Tests', function() {
|
|
|
596
620
|
********************************************************************/
|
|
597
621
|
|
|
598
622
|
it('function _date when called after configure() with defined custom format (year:2-digit) should return ' +
|
|
599
|
-
'date "95" when language is "en"', function() {
|
|
600
|
-
HandlebarsI18n.configure('en', 'DateTimeFormat', {
|
|
623
|
+
'date "95" when language is "en"', function () {
|
|
624
|
+
HandlebarsI18n.configure('en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format');
|
|
601
625
|
i18next.changeLanguage('en');
|
|
602
|
-
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {
|
|
626
|
+
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-custom-format'}});
|
|
603
627
|
assert.equal('95', res);
|
|
604
628
|
});
|
|
605
629
|
|
|
606
630
|
it('function _date when called after configure() with defined custom format (year:numeric) given as ARRAY should return ' +
|
|
607
|
-
'date "12/17/95" when language is "en"', function() {
|
|
608
|
-
HandlebarsI18n.configure(['en', 'DateTimeFormat', {
|
|
631
|
+
'date "12/17/95" when language is "en"', function () {
|
|
632
|
+
HandlebarsI18n.configure(['en', 'DateTimeFormat', {year: "numeric"}, 'my-custom-format']);
|
|
609
633
|
i18next.changeLanguage('en');
|
|
610
|
-
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {
|
|
634
|
+
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-custom-format'}});
|
|
611
635
|
assert.equal('95', res);
|
|
612
636
|
});
|
|
613
637
|
|
|
614
638
|
it('function _date when called after configure() with defined custom format (year:2-digit) should override ' +
|
|
615
|
-
'standard configuration when language is "en"', function() {
|
|
639
|
+
'standard configuration when language is "en"', function () {
|
|
616
640
|
HandlebarsI18n.configure([
|
|
617
|
-
['en', 'DateTimeFormat', {
|
|
618
|
-
['en', 'DateTimeFormat', {
|
|
641
|
+
['en', 'DateTimeFormat', {year: "numeric"}],
|
|
642
|
+
['en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format']
|
|
619
643
|
]);
|
|
620
644
|
i18next.changeLanguage('en');
|
|
621
|
-
const res = hI18n.helpers._date('[1995,11,17]', {
|
|
645
|
+
const res = hI18n.helpers._date('[1995,11,17]', {hash: {format: 'my-custom-format'}});
|
|
622
646
|
assert.equal('95', res);
|
|
623
647
|
});
|
|
624
648
|
|
|
625
649
|
it('function _date when called after configure() with defined custom format (year:2-digit) should override ' +
|
|
626
|
-
'standard configuration also when being defined first', function() {
|
|
650
|
+
'standard configuration also when being defined first', function () {
|
|
627
651
|
HandlebarsI18n.configure([
|
|
628
|
-
['en', 'DateTimeFormat', {
|
|
629
|
-
['en', 'DateTimeFormat', {
|
|
652
|
+
['en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format'],
|
|
653
|
+
['en', 'DateTimeFormat', {year: "numeric"}]
|
|
630
654
|
]);
|
|
631
655
|
i18next.changeLanguage('en');
|
|
632
|
-
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {
|
|
656
|
+
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-custom-format'}});
|
|
633
657
|
assert.equal('95', res);
|
|
634
658
|
});
|
|
635
659
|
|
|
636
660
|
it('function _date when called after configure() should fall back to generic language format "en" when custom format is unknown' +
|
|
637
|
-
'standard configuration also when being defined first', function() {
|
|
661
|
+
'standard configuration also when being defined first', function () {
|
|
638
662
|
HandlebarsI18n.configure([
|
|
639
|
-
['en', 'DateTimeFormat', {
|
|
640
|
-
['en', 'DateTimeFormat', {
|
|
663
|
+
['en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format'],
|
|
664
|
+
['en', 'DateTimeFormat', {year: "numeric"}]
|
|
641
665
|
]);
|
|
642
666
|
i18next.changeLanguage('en');
|
|
643
|
-
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {
|
|
667
|
+
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-unknown-format'}});
|
|
644
668
|
assert.equal('1995', res);
|
|
645
669
|
});
|
|
646
670
|
|
|
647
671
|
it('function _date when called after configure() should fall back to generic language format "all" when custom format is unknown' +
|
|
648
|
-
'standard configuration also when being defined first', function() {
|
|
672
|
+
'standard configuration also when being defined first', function () {
|
|
649
673
|
HandlebarsI18n.configure([
|
|
650
|
-
['all', 'DateTimeFormat', {
|
|
651
|
-
['en', 'DateTimeFormat', {
|
|
674
|
+
['all', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format'],
|
|
675
|
+
['en', 'DateTimeFormat', {year: "numeric"}]
|
|
652
676
|
]);
|
|
653
677
|
i18next.changeLanguage('en');
|
|
654
|
-
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {
|
|
678
|
+
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-unknown-format'}});
|
|
655
679
|
assert.equal('1995', res);
|
|
656
680
|
});
|
|
657
681
|
|
|
658
682
|
it('function _date when called after configure() should fall back to Intl default format when custom format is unknown' +
|
|
659
|
-
'standard configuration also when being defined first', function() {
|
|
683
|
+
'standard configuration also when being defined first', function () {
|
|
660
684
|
HandlebarsI18n.reset();
|
|
661
685
|
HandlebarsI18n.configure([
|
|
662
|
-
['en', 'DateTimeFormat', {
|
|
686
|
+
['en', 'DateTimeFormat', {year: "2-digit"}, 'my-custom-format']
|
|
663
687
|
]);
|
|
664
688
|
i18next.changeLanguage('en');
|
|
665
|
-
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {
|
|
689
|
+
const res = hI18n.helpers._date('December 17, 1995 03:24:00', {hash: {format: 'my-unknown-format'}});
|
|
666
690
|
assert.equal('12/17/1995', res);
|
|
667
691
|
});
|
|
668
692
|
|
|
@@ -672,51 +696,51 @@ describe('handlebars-i18n Tests', function() {
|
|
|
672
696
|
********************************************************************/
|
|
673
697
|
|
|
674
698
|
it('function _dateRel called after configure() with defined "all" (style: "long", unit: "second") should return ' +
|
|
675
|
-
'"in 12 seconds" when language is "en"', function() {
|
|
676
|
-
HandlebarsI18n.configure('all', 'RelativeTimeFormat', {
|
|
699
|
+
'"in 12 seconds" when language is "en"', function () {
|
|
700
|
+
HandlebarsI18n.configure('all', 'RelativeTimeFormat', {style: "long", unit: "second"});
|
|
677
701
|
i18next.changeLanguage('en');
|
|
678
702
|
const res = hI18n.helpers._dateRel('12');
|
|
679
703
|
assert.equal('in 12 seconds', res);
|
|
680
704
|
});
|
|
681
705
|
|
|
682
706
|
it('function _dateRel called after configure() with defined custom format (style: "long", unit: "year") should return ' +
|
|
683
|
-
'"in 12 Jahren" when language is "de"', function() {
|
|
684
|
-
HandlebarsI18n.configure('de', 'RelativeTimeFormat', {
|
|
707
|
+
'"in 12 Jahren" when language is "de"', function () {
|
|
708
|
+
HandlebarsI18n.configure('de', 'RelativeTimeFormat', {style: "long", unit: "year"}, 'date-rel-custom');
|
|
685
709
|
i18next.changeLanguage('de');
|
|
686
|
-
const res = hI18n.helpers._dateRel('12', {
|
|
710
|
+
const res = hI18n.helpers._dateRel('12', {hash: {format: 'date-rel-custom'}});
|
|
687
711
|
assert.equal('in 12 Jahren', res);
|
|
688
712
|
});
|
|
689
713
|
|
|
690
714
|
it('function _dateRel called after configure() with defined custom format { style: "short", unit: "minutes" } should override ' +
|
|
691
|
-
'standard configuration when language is "en"', function() {
|
|
715
|
+
'standard configuration when language is "en"', function () {
|
|
692
716
|
HandlebarsI18n.configure([
|
|
693
|
-
['en', 'RelativeTimeFormat', {
|
|
694
|
-
['en', 'RelativeTimeFormat', {
|
|
717
|
+
['en', 'RelativeTimeFormat', {style: "short", unit: "day"}, 'date-rel-spec'],
|
|
718
|
+
['en', 'RelativeTimeFormat', {style: "long", unit: "second"}]
|
|
695
719
|
]);
|
|
696
720
|
i18next.changeLanguage('en');
|
|
697
|
-
const res = hI18n.helpers._dateRel('12', {
|
|
721
|
+
const res = hI18n.helpers._dateRel('12', {hash: {format: 'date-rel-spec'}});
|
|
698
722
|
assert.equal('in 12 days', res);
|
|
699
723
|
});
|
|
700
724
|
|
|
701
725
|
it('function _dateRel called after configure() with defined custom format { style: "short", unit: "minutes" } should override ' +
|
|
702
|
-
'standard configuration when language is "en" and output: \'in 12 days\'', function() {
|
|
726
|
+
'standard configuration when language is "en" and output: \'in 12 days\'', function () {
|
|
703
727
|
HandlebarsI18n.configure([
|
|
704
|
-
['en', 'RelativeTimeFormat', {
|
|
705
|
-
['en', 'RelativeTimeFormat', {
|
|
728
|
+
['en', 'RelativeTimeFormat', {style: "short", unit: "day"}, 'date-rel-spec'],
|
|
729
|
+
['en', 'RelativeTimeFormat', {style: "long", unit: "second"}]
|
|
706
730
|
]);
|
|
707
731
|
i18next.changeLanguage('en');
|
|
708
|
-
const res = hI18n.helpers._dateRel('12', {
|
|
732
|
+
const res = hI18n.helpers._dateRel('12', {hash: {format: 'date-rel-spec'}});
|
|
709
733
|
assert.equal('in 12 days', res);
|
|
710
734
|
});
|
|
711
735
|
|
|
712
736
|
it('function _dateDiff called after configure() with defined custom format { style: "short", unit: "minutes" } should override ' +
|
|
713
|
-
'standard configuration when language is "en" and output: \'in in 1 yr.\'', function() {
|
|
737
|
+
'standard configuration when language is "en" and output: \'in in 1 yr.\'', function () {
|
|
714
738
|
HandlebarsI18n.configure([
|
|
715
|
-
['en', 'RelativeTimeFormat', {
|
|
716
|
-
['en', 'RelativeTimeFormat', {
|
|
739
|
+
['en', 'RelativeTimeFormat', {style: "short", unit: "year"}, 'date-rel-spec'],
|
|
740
|
+
['en', 'RelativeTimeFormat', {style: "long", unit: "day"}]
|
|
717
741
|
]);
|
|
718
742
|
i18next.changeLanguage('en');
|
|
719
|
-
const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1995-12-17T00:00:00',{
|
|
743
|
+
const res = hI18n.helpers._dateDiff('1996-12-17T00:00:00', '1995-12-17T00:00:00', {hash: {format: 'date-rel-spec'}});
|
|
720
744
|
assert.equal('in 1 yr.', res);
|
|
721
745
|
});
|
|
722
746
|
|
|
@@ -726,70 +750,70 @@ describe('handlebars-i18n Tests', function() {
|
|
|
726
750
|
********************************************************************/
|
|
727
751
|
|
|
728
752
|
it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
|
|
729
|
-
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
|
|
730
|
-
HandlebarsI18n.configure('en', 'NumberFormat', {
|
|
753
|
+
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
|
|
754
|
+
HandlebarsI18n.configure('en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format');
|
|
731
755
|
i18next.changeLanguage('en');
|
|
732
|
-
const res = hI18n.helpers._num(4000000, {
|
|
756
|
+
const res = hI18n.helpers._num(4000000, {hash: {format: 'my-custom-format'}});
|
|
733
757
|
assert.equal('4,000,000.0000', res);
|
|
734
758
|
});
|
|
735
759
|
|
|
736
760
|
it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) given as ARRAY should return ' +
|
|
737
|
-
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
|
|
738
|
-
HandlebarsI18n.configure(['en', 'NumberFormat', {
|
|
761
|
+
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
|
|
762
|
+
HandlebarsI18n.configure(['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format']);
|
|
739
763
|
i18next.changeLanguage('en');
|
|
740
|
-
const res = hI18n.helpers._num(4000000, {
|
|
764
|
+
const res = hI18n.helpers._num(4000000, {hash: {format: 'my-custom-format'}});
|
|
741
765
|
assert.equal('4,000,000.0000', res);
|
|
742
766
|
});
|
|
743
767
|
|
|
744
768
|
it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should override' +
|
|
745
|
-
'standard configuration when language is "en"', function() {
|
|
769
|
+
'standard configuration when language is "en"', function () {
|
|
746
770
|
HandlebarsI18n.configure([
|
|
747
|
-
['en', 'NumberFormat', {
|
|
748
|
-
['en', 'NumberFormat', {
|
|
771
|
+
['en', 'NumberFormat', {maximumFractionDigits: 1}],
|
|
772
|
+
['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format']
|
|
749
773
|
]);
|
|
750
774
|
i18next.changeLanguage('en');
|
|
751
|
-
const res = hI18n.helpers._num(4000000, {
|
|
775
|
+
const res = hI18n.helpers._num(4000000, {hash: {format: 'my-custom-format'}});
|
|
752
776
|
assert.equal('4,000,000.0000', res);
|
|
753
777
|
});
|
|
754
778
|
|
|
755
779
|
it('function _num when called after configure() with defined custom format (minimumFractionDigits:4) should override' +
|
|
756
|
-
'standard configuration also when being defined first', function() {
|
|
780
|
+
'standard configuration also when being defined first', function () {
|
|
757
781
|
HandlebarsI18n.configure([
|
|
758
|
-
['en', 'NumberFormat', {
|
|
759
|
-
['en', 'NumberFormat', {
|
|
782
|
+
['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format'],
|
|
783
|
+
['en', 'NumberFormat', {maximumFractionDigits: 1}]
|
|
760
784
|
]);
|
|
761
785
|
i18next.changeLanguage('en');
|
|
762
|
-
const res = hI18n.helpers._num(4000000, {
|
|
786
|
+
const res = hI18n.helpers._num(4000000, {hash: {format: 'my-custom-format'}});
|
|
763
787
|
assert.equal('4,000,000.0000', res);
|
|
764
788
|
});
|
|
765
789
|
|
|
766
|
-
it('function _num when called after configure() should fall back to standard language format "en" when custom format is unknown', function() {
|
|
790
|
+
it('function _num when called after configure() should fall back to standard language format "en" when custom format is unknown', function () {
|
|
767
791
|
HandlebarsI18n.configure([
|
|
768
|
-
['en', 'NumberFormat', {
|
|
769
|
-
['en', 'NumberFormat', {
|
|
792
|
+
['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format'],
|
|
793
|
+
['en', 'NumberFormat', {minimumFractionDigits: 1}]
|
|
770
794
|
]);
|
|
771
795
|
i18next.changeLanguage('en');
|
|
772
|
-
const res = hI18n.helpers._num(4000000, {
|
|
796
|
+
const res = hI18n.helpers._num(4000000, {hash: {format: 'my-unknown-format'}});
|
|
773
797
|
assert.equal('4,000,000.0', res);
|
|
774
798
|
});
|
|
775
799
|
|
|
776
|
-
it('function _num when called after configure() should fall back to standard language format "all" when custom format is unknown', function() {
|
|
800
|
+
it('function _num when called after configure() should fall back to standard language format "all" when custom format is unknown', function () {
|
|
777
801
|
HandlebarsI18n.configure([
|
|
778
|
-
['en', 'NumberFormat', {
|
|
779
|
-
['all', 'NumberFormat', {
|
|
802
|
+
['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format'],
|
|
803
|
+
['all', 'NumberFormat', {minimumFractionDigits: 1}]
|
|
780
804
|
]);
|
|
781
805
|
i18next.changeLanguage('en');
|
|
782
|
-
const res = hI18n.helpers._num(4000000, {
|
|
806
|
+
const res = hI18n.helpers._num(4000000, {hash: {format: 'my-unknown-format'}});
|
|
783
807
|
assert.equal('4,000,000.0', res);
|
|
784
808
|
});
|
|
785
809
|
|
|
786
|
-
it('function _num when called after configure() should fall back to Intl default when custom format is unknown', function() {
|
|
810
|
+
it('function _num when called after configure() should fall back to Intl default when custom format is unknown', function () {
|
|
787
811
|
HandlebarsI18n.reset();
|
|
788
812
|
HandlebarsI18n.configure([
|
|
789
|
-
['en', 'NumberFormat', {
|
|
813
|
+
['en', 'NumberFormat', {minimumFractionDigits: 4}, 'my-custom-format']
|
|
790
814
|
]);
|
|
791
815
|
i18next.changeLanguage('en');
|
|
792
|
-
const res = hI18n.helpers._num(4000000, {
|
|
816
|
+
const res = hI18n.helpers._num(4000000, {hash: {format: 'my-unknown-format'}});
|
|
793
817
|
assert.equal('4,000,000', res);
|
|
794
818
|
});
|
|
795
819
|
|
|
@@ -799,77 +823,77 @@ describe('handlebars-i18n Tests', function() {
|
|
|
799
823
|
********************************************************************/
|
|
800
824
|
|
|
801
825
|
it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
|
|
802
|
-
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
|
|
803
|
-
HandlebarsI18n.configure('en', 'PriceFormat', {
|
|
826
|
+
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
|
|
827
|
+
HandlebarsI18n.configure('en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format');
|
|
804
828
|
i18next.changeLanguage('en');
|
|
805
|
-
const res = hI18n.helpers._price(2, {
|
|
829
|
+
const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
|
|
806
830
|
assert.equal('€2.000', res);
|
|
807
831
|
});
|
|
808
832
|
|
|
809
833
|
it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) should return ' +
|
|
810
|
-
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
|
|
811
|
-
HandlebarsI18n.configure('en', 'PriceFormat', {
|
|
834
|
+
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
|
|
835
|
+
HandlebarsI18n.configure('en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format');
|
|
812
836
|
i18next.changeLanguage('en');
|
|
813
|
-
const res = hI18n.helpers._price(2, {
|
|
837
|
+
const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
|
|
814
838
|
assert.equal('€2.000', res);
|
|
815
839
|
});
|
|
816
840
|
|
|
817
841
|
it('function _price when called after configure() with defined custom format (minimumFractionDigits:4) given as ARRAY should return ' +
|
|
818
|
-
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function() {
|
|
819
|
-
HandlebarsI18n.configure(['en', 'PriceFormat', {
|
|
842
|
+
'comma separated triples of decimals and 4 fraction of digits when language is "en"', function () {
|
|
843
|
+
HandlebarsI18n.configure(['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format']);
|
|
820
844
|
i18next.changeLanguage('en');
|
|
821
|
-
const res = hI18n.helpers._price(2, {
|
|
845
|
+
const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
|
|
822
846
|
assert.equal('€2.000', res);
|
|
823
847
|
});
|
|
824
848
|
|
|
825
849
|
it('function _price when called after configure() with defined custom format (minimumFractionDigits:3) should override' +
|
|
826
|
-
'standard configuration when language is "en"', function() {
|
|
850
|
+
'standard configuration when language is "en"', function () {
|
|
827
851
|
HandlebarsI18n.configure([
|
|
828
|
-
['en', 'PriceFormat', {
|
|
829
|
-
['en', 'PriceFormat', {
|
|
852
|
+
['en', 'PriceFormat', {currency: 'USD'}],
|
|
853
|
+
['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format']
|
|
830
854
|
]);
|
|
831
855
|
i18next.changeLanguage('en');
|
|
832
|
-
const res = hI18n.helpers._price(2, {
|
|
856
|
+
const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
|
|
833
857
|
assert.equal('€2.000', res);
|
|
834
858
|
});
|
|
835
859
|
|
|
836
860
|
it('function _price when called after configure() with defined custom format (minimumFractionDigits:3) should override' +
|
|
837
|
-
'standard configuration also when being defined first', function() {
|
|
861
|
+
'standard configuration also when being defined first', function () {
|
|
838
862
|
HandlebarsI18n.configure([
|
|
839
|
-
['en', 'PriceFormat', {
|
|
840
|
-
['en', 'PriceFormat', {
|
|
863
|
+
['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format'],
|
|
864
|
+
['en', 'PriceFormat', {currency: 'USD'}]
|
|
841
865
|
]);
|
|
842
866
|
i18next.changeLanguage('en');
|
|
843
|
-
const res = hI18n.helpers._price(2, {
|
|
867
|
+
const res = hI18n.helpers._price(2, {hash: {format: 'my-custom-format'}});
|
|
844
868
|
assert.equal('€2.000', res);
|
|
845
869
|
});
|
|
846
870
|
|
|
847
|
-
it('function _price when called after configure() should fall back to standard language format "en" when custom format is unknown', function() {
|
|
871
|
+
it('function _price when called after configure() should fall back to standard language format "en" when custom format is unknown', function () {
|
|
848
872
|
HandlebarsI18n.configure([
|
|
849
|
-
['en', 'PriceFormat', {
|
|
850
|
-
['en', 'PriceFormat', {
|
|
873
|
+
['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format'],
|
|
874
|
+
['en', 'PriceFormat', {currency: 'USD'}]
|
|
851
875
|
]);
|
|
852
876
|
i18next.changeLanguage('en');
|
|
853
|
-
const res = hI18n.helpers._price(2, {
|
|
877
|
+
const res = hI18n.helpers._price(2, {hash: {format: 'my-unknown-format'}});
|
|
854
878
|
assert.equal('$2.00', res);
|
|
855
879
|
});
|
|
856
880
|
|
|
857
|
-
it('function _price when called after configure() should fall back to standard language format "all" when custom format is unknown', function() {
|
|
881
|
+
it('function _price when called after configure() should fall back to standard language format "all" when custom format is unknown', function () {
|
|
858
882
|
HandlebarsI18n.configure([
|
|
859
|
-
['en', 'PriceFormat', {
|
|
860
|
-
['all', 'PriceFormat', {
|
|
883
|
+
['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format'],
|
|
884
|
+
['all', 'PriceFormat', {currency: 'USD'}]
|
|
861
885
|
]);
|
|
862
886
|
i18next.changeLanguage('en');
|
|
863
|
-
const res = hI18n.helpers._price(2, {
|
|
887
|
+
const res = hI18n.helpers._price(2, {hash: {format: 'my-unknown-format'}});
|
|
864
888
|
assert.equal('$2.00', res);
|
|
865
889
|
});
|
|
866
890
|
|
|
867
|
-
it('function _price when called after configure() should fall back to Intl default when custom format is unknown', function() {
|
|
891
|
+
it('function _price when called after configure() should fall back to Intl default when custom format is unknown', function () {
|
|
868
892
|
HandlebarsI18n.configure([
|
|
869
|
-
['en', 'PriceFormat', {
|
|
893
|
+
['en', 'PriceFormat', {currency: 'EUR', minimumFractionDigits: 3}, 'my-custom-format']
|
|
870
894
|
]);
|
|
871
895
|
i18next.changeLanguage('en');
|
|
872
|
-
const res = hI18n.helpers._price(2, {
|
|
896
|
+
const res = hI18n.helpers._price(2, {hash: {format: 'my-unknown-format'}});
|
|
873
897
|
assert.equal('$2.00', res);
|
|
874
898
|
});
|
|
875
899
|
|
|
@@ -895,12 +919,12 @@ describe('handlebars-i18n Private helper Function Tests (in production not expor
|
|
|
895
919
|
expect(instance.b).to.equal(2);
|
|
896
920
|
});
|
|
897
921
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
922
|
+
/* it('should handle no arguments', () => {
|
|
923
|
+
const instance = HandlebarsI18n.private.applyToConstructor(TestConstructor, []);
|
|
924
|
+
expect(instance).to.be.an.instanceof(TestConstructor);
|
|
925
|
+
expect(instance.a).to.equal(null);
|
|
926
|
+
expect(instance.b).to.equal(undefined); // because 'undefined' is passed as second argument
|
|
927
|
+
});*/
|
|
904
928
|
|
|
905
929
|
it('should handle constructor with no arguments', () => {
|
|
906
930
|
function ConstructorWithNoArgs() {
|
|
@@ -920,6 +944,7 @@ describe('handlebars-i18n Private helper Function Tests (in production not expor
|
|
|
920
944
|
}
|
|
921
945
|
|
|
922
946
|
const args = [new ComplexArgument(5)];
|
|
947
|
+
|
|
923
948
|
function ConstructorWithComplexArg(arg) {
|
|
924
949
|
this.arg = arg;
|
|
925
950
|
}
|
|
@@ -944,12 +969,12 @@ describe('handlebars-i18n Private helper Function Tests (in production not expor
|
|
|
944
969
|
const lang = 'en';
|
|
945
970
|
const OCFormat = {
|
|
946
971
|
standard: {
|
|
947
|
-
en: { /* Standard configuration for English */
|
|
948
|
-
all: { /* Universal configuration for all languages */
|
|
972
|
+
en: { /* Standard configuration for English */},
|
|
973
|
+
all: { /* Universal configuration for all languages */}
|
|
949
974
|
},
|
|
950
975
|
custom: {
|
|
951
976
|
customFormat: {
|
|
952
|
-
en: { /* Custom configuration for English */
|
|
977
|
+
en: { /* Custom configuration for English */}
|
|
953
978
|
}
|
|
954
979
|
}
|
|
955
980
|
};
|
|
@@ -985,5 +1010,4 @@ describe('handlebars-i18n Private helper Function Tests (in production not expor
|
|
|
985
1010
|
expect(result).to.deep.equal({});
|
|
986
1011
|
});
|
|
987
1012
|
|
|
988
|
-
|
|
989
1013
|
});
|