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