i18n-js 0.1.6 → 1.0.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.
data/test/i18n-test.js DELETED
@@ -1,692 +0,0 @@
1
- new Test.Unit.Runner({
2
- setup: function() {
3
- I18n.defaultLocale = "en";
4
- I18n.defaultSeparator = ".";
5
- I18n.locale = null;
6
-
7
- I18n.translations = {
8
- en: {
9
- hello: "Hello World!",
10
- greetings: {
11
- stranger: "Hello stranger!",
12
- name: "Hello {{name}}!"
13
- },
14
- profile: {
15
- details: "{{name}} is {{age}}-years old"
16
- },
17
- inbox: {
18
- one: "You have {{count}} message",
19
- other: "You have {{count}} messages",
20
- zero: "You have no messages"
21
- },
22
- unread: {
23
- one: "You have 1 new message ({{unread}} unread)",
24
- other: "You have {{count}} new messages ({{unread}} unread)",
25
- zero: "You have no new messages ({{unread}} unread)"
26
- },
27
- number: null
28
- },
29
-
30
- pt: {
31
- hello: "Olá Mundo!",
32
- date: {
33
- formats: {
34
- "default": "%d/%m/%Y",
35
- "short": "%d de %B",
36
- "long": "%d de %B de %Y"
37
- },
38
- day_names: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"],
39
- abbr_day_names: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"],
40
- month_names: [null, "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
41
- abbr_month_names: [null, "Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]
42
- },
43
- number: {
44
- percentage: {
45
- format: {
46
- delimiter: "",
47
- separator: ",",
48
- precision: 2
49
- }
50
- }
51
- },
52
- time: {
53
- formats: {
54
- "default": "%A, %d de %B de %Y, %H:%M h",
55
- "short": "%d/%m, %H:%M h",
56
- "long": "%A, %d de %B de %Y, %H:%M h"
57
- },
58
- am: "AM",
59
- pm: "PM"
60
- }
61
- }
62
- }
63
- },
64
-
65
- teardown: function() {
66
- },
67
-
68
- // Defaults
69
- testDefaults: function() { with(this) {
70
- assertEqual("en", I18n.defaultLocale);
71
- assertEqual(null, I18n.locale);
72
- assertEqual("en", I18n.currentLocale());
73
- }},
74
-
75
- // Custom locale
76
- testCustomLocale: function() { with(this) {
77
- I18n.locale = "pt";
78
- assertEqual("pt", I18n.currentLocale());
79
- }},
80
-
81
- // Aliases methods
82
- testAliasesMethods: function() { with(this) {
83
- assertEqual(I18n.translate, I18n.t);
84
- assertEqual(I18n.localize, I18n.l);
85
- assertEqual(I18n.pluralize, I18n.p);
86
- }},
87
-
88
- // Translation for single scope
89
- testTranslationForSingleScope: function() { with(this) {
90
- assertEqual("Hello World!", I18n.translate("hello"));
91
- }},
92
-
93
- // Translation as object
94
- testTranslationAsObject: function() { with(this) {
95
- assertEqual("object", typeof I18n.translate("greetings"));
96
- }},
97
-
98
- // Translation with invalid scope shall not block
99
- testTranslationWithInvalidScope: function() { with(this) {
100
- assertEqual('[missing "en.invalid.scope.shall.not.block" translation]', I18n.translate("invalid.scope.shall.not.block"));
101
- }},
102
-
103
- // Translation for single scope on a custom locale
104
- testTranslationForSingleScopeOnACustomLocale: function() { with(this) {
105
- I18n.locale = "pt";
106
- assertEqual("Olá Mundo!", I18n.translate("hello"));
107
- }},
108
-
109
- // Translation for multiple scopes
110
- testTranslationForMultipleScopes: function() { with(this) {
111
- assertEqual("Hello stranger!", I18n.translate("greetings.stranger"));
112
- }},
113
-
114
- // Single interpolation
115
- testSingleInterpolation: function() { with(this) {
116
- actual = I18n.translate("greetings.name", {name: "John Doe"});
117
- assertEqual("Hello John Doe!", actual);
118
- }},
119
-
120
- // Multiple interpolations
121
- testMultipleInterpolations: function() { with(this) {
122
- actual = I18n.translate("profile.details", {name: "John Doe", age: 27});
123
- assertEqual("John Doe is 27-years old", actual);
124
- }},
125
-
126
- // Translation with count option
127
- testTranslationWithCountOption: function() { with(this) {
128
- assertEqual("You have 1 message", I18n.translate("inbox", {count: 1}));
129
- assertEqual("You have 5 messages", I18n.translate("inbox", {count: 5}));
130
- assertEqual("You have no messages", I18n.translate("inbox", {count: 0}));
131
- }},
132
-
133
- // Translation with count option and multiple placeholders
134
- testTranslationWithCountOptionAndMultiplePlaceholders: function() { with(this) {
135
- actual = I18n.translate("unread", {unread: 5, count: 1});
136
- assertEqual("You have 1 new message (5 unread)", actual);
137
-
138
- actual = I18n.translate("unread", {unread: 2, count: 10});
139
- assertEqual("You have 10 new messages (2 unread)", actual);
140
-
141
- actual = I18n.translate("unread", {unread: 5, count: 0});
142
- assertEqual("You have no new messages (5 unread)", actual);
143
- }},
144
-
145
- // Missing translation with count option
146
- testMissingTranslationWithCountOption: function() { with(this) {
147
- actual = I18n.translate("invalid", {count: 1});
148
- assertEqual('[missing "en.invalid" translation]', actual);
149
-
150
- I18n.translations.en.inbox.one = null;
151
- actual = I18n.translate("inbox", {count: 1});
152
- assertEqual('[missing "en.inbox.one" translation]', actual);
153
- }},
154
-
155
- // Pluralization
156
- testPluralization: function() { with(this) {
157
- assertEqual("You have 1 message", I18n.pluralize(1, "inbox"));
158
- assertEqual("You have 5 messages", I18n.pluralize(5, "inbox"));
159
- assertEqual("You have no messages", I18n.pluralize(0, "inbox"));
160
- }},
161
-
162
- // Pluralize should return "other" scope
163
- testPluralizeShouldReturnOtherScope: function() { with(this) {
164
- I18n.translations["en"]["inbox"]["zero"] = null;
165
- assertEqual("You have 0 messages", I18n.pluralize(0, "inbox"));
166
- }},
167
-
168
- // Pluralize should return "zero" scope
169
- testPluralizeShouldReturnZeroScope: function() { with(this) {
170
- I18n.translations["en"]["inbox"]["zero"] = "No messages (zero)";
171
- I18n.translations["en"]["inbox"]["none"] = "No messages (none)";
172
-
173
- assertEqual("No messages (zero)", I18n.pluralize(0, "inbox"));
174
- }},
175
-
176
- // Pluralize should return "none" scope
177
- testPluralizeShouldReturnNoneScope: function() { with(this) {
178
- I18n.translations["en"]["inbox"]["zero"] = null;
179
- I18n.translations["en"]["inbox"]["none"] = "No messages (none)";
180
-
181
- assertEqual("No messages (none)", I18n.pluralize(0, "inbox"));
182
- }},
183
-
184
- // Pluralize with negative values
185
- testPluralizeWithNegativeValues: function() { with(this) {
186
- assertEqual("You have -1 message", I18n.pluralize(-1, "inbox"));
187
- assertEqual("You have -5 messages", I18n.pluralize(-5, "inbox"));
188
- }},
189
-
190
- // Pluralize with missing scope
191
- testPluralizeWithMissingScope: function() { with(this) {
192
- assertEqual('[missing "en.missing" translation]', I18n.pluralize(-1, "missing"));
193
- }},
194
-
195
- // Pluralize with multiple placeholders
196
- testPluralizeWithMultiplePlaceholders: function() { with(this) {
197
- actual = I18n.pluralize(1, "unread", {unread: 5});
198
- assertEqual("You have 1 new message (5 unread)", actual);
199
-
200
- actual = I18n.pluralize(10, "unread", {unread: 2});
201
- assertEqual("You have 10 new messages (2 unread)", actual);
202
-
203
- actual = I18n.pluralize(0, "unread", {unread: 5});
204
- assertEqual("You have no new messages (5 unread)", actual);
205
- }},
206
-
207
- // Numbers with default settings
208
- testNumbersWithDefaultSettings: function() { with(this) {
209
- assertEqual("1.000", I18n.toNumber(1));
210
- assertEqual("12.000", I18n.toNumber(12));
211
- assertEqual("123.000", I18n.toNumber(123));
212
- assertEqual("1,234.000", I18n.toNumber(1234));
213
- assertEqual("123,456.000", I18n.toNumber(123456));
214
- assertEqual("1,234,567.000", I18n.toNumber(1234567));
215
- assertEqual("12,345,678.000", I18n.toNumber(12345678));
216
- }},
217
-
218
- // Negative numbers with default settings
219
- testNegativeNumbersWithDefaultSettings: function() { with(this) {
220
- assertEqual("-1.000", I18n.toNumber(-1));
221
- assertEqual("-12.000", I18n.toNumber(-12));
222
- assertEqual("-123.000", I18n.toNumber(-123));
223
- assertEqual("-1,234.000", I18n.toNumber(-1234));
224
- assertEqual("-123,456.000", I18n.toNumber(-123456));
225
- assertEqual("-1,234,567.000", I18n.toNumber(-1234567));
226
- assertEqual("-12,345,678.000", I18n.toNumber(-12345678));
227
- }},
228
-
229
- // Numbers with partial translation and default options
230
- testNumbersWithPartialTranslationAndDefaultOptions: function() { with(this) {
231
- I18n.translations.en.number = {
232
- format: {
233
- precision: 2
234
- }
235
- }
236
-
237
- assertEqual("1,234.00", I18n.toNumber(1234));
238
- }},
239
-
240
- // Numbers with full translation and default options
241
- testNumbersWithFullTranslationAndDefaultOptions: function() { with(this) {
242
- I18n.translations.en.number = {
243
- format: {
244
- delimiter: ".",
245
- separator: ",",
246
- precision: 2
247
- }
248
- }
249
-
250
- assertEqual("1.234,00", I18n.toNumber(1234));
251
- }},
252
-
253
- // Numbers with some custom options that should be merged with default options
254
- testNumbersWithSomeCustomOptionsThatShouldBeMergedWithDefaultOptions: function() { with(this) {
255
- assertEqual("1,234", I18n.toNumber(1234, {precision: 0}));
256
- assertEqual("1,234-000", I18n.toNumber(1234, {separator: "-"}));
257
- assertEqual("1-234.000", I18n.toNumber(1234, {delimiter: "-"}));
258
- }},
259
-
260
- // Numbers considering options
261
- testNumbersConsideringOptions: function() { with(this) {
262
- options = {
263
- precision: 2,
264
- separator: ",",
265
- delimiter: "."
266
- };
267
-
268
- assertEqual("1,00", I18n.toNumber(1, options));
269
- assertEqual("12,00", I18n.toNumber(12, options));
270
- assertEqual("123,00", I18n.toNumber(123, options));
271
- assertEqual("1.234,00", I18n.toNumber(1234, options));
272
- assertEqual("123.456,00", I18n.toNumber(123456, options));
273
- assertEqual("1.234.567,00", I18n.toNumber(1234567, options));
274
- assertEqual("12.345.678,00", I18n.toNumber(12345678, options));
275
- }},
276
-
277
- // Numbers with different precisions
278
- testNumbersWithDifferentPrecisions: function() { with(this) {
279
- options = {separator: ".", delimiter: ","};
280
-
281
- options["precision"] = 2;
282
- assertEqual("1.98", I18n.toNumber(1.98, options));
283
-
284
- options["precision"] = 3;
285
- assertEqual("1.980", I18n.toNumber(1.98, options));
286
-
287
- options["precision"] = 2;
288
- assertEqual("1.99", I18n.toNumber(1.987, options));
289
-
290
- options["precision"] = 1;
291
- assertEqual("2.0", I18n.toNumber(1.98, options));
292
-
293
- options["precision"] = 0;
294
- assertEqual("2", I18n.toNumber(1.98, options));
295
- }},
296
-
297
- // Currency with default settings
298
- testCurrencyWithDefaultSettings: function() { with(this) {
299
- assertEqual("$100.99", I18n.toCurrency(100.99));
300
- assertEqual("$1,000.99", I18n.toCurrency(1000.99));
301
- }},
302
-
303
- // Current with custom settings
304
- testCurrencyWithCustomSettings: function() { with(this) {
305
- I18n.translations.en.number = {
306
- currency: {
307
- format: {
308
- format: "%n %u",
309
- unit: "USD",
310
- delimiter: ".",
311
- separator: ",",
312
- precision: 2
313
- }
314
- }
315
- };
316
-
317
- assertEqual("12,00 USD", I18n.toCurrency(12));
318
- assertEqual("123,00 USD", I18n.toCurrency(123));
319
- assertEqual("1.234,56 USD", I18n.toCurrency(1234.56));
320
- }},
321
-
322
- // Currency with custom settings and partial overriding
323
- testCurrencyWithCustomSettingsAndPartialOverriding: function() { with(this) {
324
- I18n.translations.en.number = {
325
- currency: {
326
- format: {
327
- format: "%n %u",
328
- unit: "USD",
329
- delimiter: ".",
330
- separator: ",",
331
- precision: 2
332
- }
333
- }
334
- };
335
-
336
- assertEqual("12 USD", I18n.toCurrency(12, {precision: 0}));
337
- assertEqual("123,00 bucks", I18n.toCurrency(123, {unit: "bucks"}));
338
- }},
339
-
340
- // Currency with some custom options that should be merged with default options
341
- testCurrencyWithSomeCustomOptionsThatShouldBeMergedWithDefaultOptions: function() { with(this) {
342
- assertEqual("$1,234", I18n.toCurrency(1234, {precision: 0}));
343
- assertEqual("º1,234.00", I18n.toCurrency(1234, {unit: "º"}));
344
- assertEqual("$1,234-00", I18n.toCurrency(1234, {separator: "-"}));
345
- assertEqual("$1-234.00", I18n.toCurrency(1234, {delimiter: "-"}));
346
- assertEqual("$ 1,234.00", I18n.toCurrency(1234, {format: "%u %n"}));
347
- }},
348
-
349
- // Localize numbers
350
- testLocalizeNumbers: function() { with(this) {
351
- assertEqual("1,234,567.000", I18n.localize("number", 1234567));
352
- }},
353
-
354
- // Localize currency
355
- testLocalizeCurrency: function() { with(this) {
356
- assertEqual("$1,234,567.00", I18n.localize("currency", 1234567));
357
- }},
358
-
359
- // Parse date
360
- testParseDate: function() { with(this) {
361
- expected = new Date(2009, 0, 24, 0, 0, 0);
362
- assertEqual(expected.toString(), I18n.parseDate("2009-01-24").toString());
363
-
364
- expected = new Date(2009, 0, 24, 0, 15, 0);
365
- assertEqual(expected.toString(), I18n.parseDate("2009-01-24 00:15:00").toString());
366
-
367
- expected = new Date(2009, 0, 24, 0, 0, 15);
368
- assertEqual(expected.toString(), I18n.parseDate("2009-01-24 00:00:15").toString());
369
-
370
- expected = new Date(2009, 0, 24, 15, 33, 44);
371
- assertEqual(expected.toString(), I18n.parseDate("2009-01-24 15:33:44").toString());
372
-
373
- expected = new Date(2009, 0, 24, 0, 0, 0);
374
- assertEqual(expected.toString(), I18n.parseDate(expected.getTime()).toString());
375
-
376
- expected = new Date(2009, 0, 24, 0, 0, 0);
377
- assertEqual(expected.toString(), I18n.parseDate("01/24/2009").toString());
378
-
379
- expected = new Date(2009, 0, 24, 14, 33, 55);
380
- assertEqual(expected.toString(), I18n.parseDate(expected).toString());
381
-
382
- expected = new Date(2009, 0, 24, 15, 33, 44);
383
- assertEqual(expected.toString(), I18n.parseDate("2009-01-24T15:33:44").toString());
384
-
385
- expected = new Date(Date.UTC(2009, 0, 24, 15, 33, 44));
386
- assertEqual(expected.toString(), I18n.parseDate("2009-01-24T15:33:44Z").toString());
387
- }},
388
-
389
- // Date formatting
390
- testDateFormatting: function() { with(this) {
391
- I18n.locale = "pt";
392
-
393
- // 2009-04-26 19:35:44 (Sunday)
394
- var date = new Date(2009, 3, 26, 19, 35, 44);
395
-
396
- // short week day
397
- assertEqual("Dom", I18n.strftime(date, "%a"));
398
-
399
- // full week day
400
- assertEqual("Domingo", I18n.strftime(date, "%A"));
401
-
402
- // short month
403
- assertEqual("Abr", I18n.strftime(date, "%b"));
404
-
405
- // full month
406
- assertEqual("Abril", I18n.strftime(date, "%B"));
407
-
408
- // day
409
- assertEqual("26", I18n.strftime(date, "%d"));
410
-
411
- // 24-hour
412
- assertEqual("19", I18n.strftime(date, "%H"));
413
-
414
- // 12-hour
415
- assertEqual("07", I18n.strftime(date, "%I"));
416
-
417
- // month
418
- assertEqual("04", I18n.strftime(date, "%m"));
419
-
420
- // minutes
421
- assertEqual("35", I18n.strftime(date, "%M"));
422
-
423
- // meridian
424
- assertEqual("PM", I18n.strftime(date, "%p"));
425
-
426
- // seconds
427
- assertEqual("44", I18n.strftime(date, "%S"));
428
-
429
- // week day
430
- assertEqual("0", I18n.strftime(date, "%w"));
431
-
432
- // short year
433
- assertEqual("09", I18n.strftime(date, "%y"));
434
-
435
- // full year
436
- assertEqual("2009", I18n.strftime(date, "%Y"));
437
- }},
438
-
439
- // Date formatting without padding
440
- testDateFormattingWithoutPadding: function() { with(this) {
441
- I18n.locale = "pt";
442
-
443
- // 2009-04-26 19:35:44 (Sunday)
444
- var date = new Date(2009, 3, 9, 7, 8, 9);
445
-
446
- // 24-hour without padding
447
- assertEqual("7", I18n.strftime(date, "%-H"));
448
-
449
- // 12-hour without padding
450
- assertEqual("7", I18n.strftime(date, "%-I"));
451
-
452
- // minutes without padding
453
- assertEqual("8", I18n.strftime(date, "%-M"));
454
-
455
- // seconds without padding
456
- assertEqual("9", I18n.strftime(date, "%-S"));
457
-
458
- // short year without padding
459
- assertEqual("9", I18n.strftime(date, "%-y"));
460
-
461
- // month without padding
462
- assertEqual("4", I18n.strftime(date, "%-m"));
463
-
464
- // day without padding
465
- assertEqual("9", I18n.strftime(date, "%-d"));
466
- }},
467
-
468
- // Date formatting with padding
469
- testDateFormattingWithPadding: function() { with(this) {
470
- I18n.locale = "pt";
471
-
472
- // 2009-04-26 19:35:44 (Sunday)
473
- var date = new Date(2009, 3, 9, 7, 8, 9);
474
-
475
- // 24-hour
476
- assertEqual("07", I18n.strftime(date, "%H"));
477
-
478
- // 12-hour
479
- assertEqual("07", I18n.strftime(date, "%I"));
480
-
481
- // minutes
482
- assertEqual("08", I18n.strftime(date, "%M"));
483
-
484
- // seconds
485
- assertEqual("09", I18n.strftime(date, "%S"));
486
-
487
- // short year
488
- assertEqual("09", I18n.strftime(date, "%y"));
489
-
490
- // month
491
- assertEqual("04", I18n.strftime(date, "%m"));
492
-
493
- // day
494
- assertEqual("09", I18n.strftime(date, "%d"));
495
- }},
496
-
497
- // Date formatting with negative Timezone
498
- testDateFormattingWithNegativeTimezone: function() { with(this) {
499
- I18n.locale = "pt";
500
-
501
- var date = new Date(2009, 3, 26, 19, 35, 44);
502
-
503
- date.getTimezoneOffset = function() {
504
- return 345;
505
- };
506
-
507
- assertMatch(/^(\+|-)[\d]{4}$/, I18n.strftime(date, "%z"));
508
- assertEqual("-0545", I18n.strftime(date, "%z"));
509
- }},
510
-
511
- // Date formatting with positive Timezone
512
- testDateFormattingWithPositiveTimezone: function() { with(this) {
513
- I18n.locale = "pt";
514
-
515
- var date = new Date(2009, 3, 26, 19, 35, 44);
516
-
517
- date.getTimezoneOffset = function() {
518
- return -345;
519
- };
520
-
521
- assertMatch(/^(\+|-)[\d]{4}$/, I18n.strftime(date, "%z"));
522
- assertEqual("+0545", I18n.strftime(date, "%z"));
523
- }},
524
-
525
- // Localize date strings
526
- testLocalizeDateStrings: function() { with(this) {
527
- I18n.locale = "pt";
528
-
529
- assertEqual("29/11/2009", I18n.localize("date.formats.default", "2009-11-29"));
530
- assertEqual("07 de Janeiro", I18n.localize("date.formats.short", "2009-01-07"));
531
- assertEqual("07 de Janeiro de 2009", I18n.localize("date.formats.long", "2009-01-07"));
532
- }},
533
-
534
- // Localize time strings
535
- testLocalizeTimeStrings: function() { with(this) {
536
- I18n.locale = "pt";
537
- assertEqual("Domingo, 29 de Novembro de 2009, 15:07 h", I18n.localize("time.formats.default", "2009-11-29 15:07:59"));
538
- assertEqual("07/01, 09:12 h", I18n.localize("time.formats.short", "2009-01-07 09:12:35"));
539
- assertEqual("Domingo, 29 de Novembro de 2009, 15:07 h", I18n.localize("time.formats.long", "2009-11-29 15:07:59"));
540
- }},
541
-
542
- // Localize percentage
543
- testLocalizePercentage: function() { with(this) {
544
- I18n.locale = "pt";
545
- assertEqual("123,45%", I18n.localize("percentage", 123.45));
546
- }},
547
-
548
-
549
-
550
- // Default value for simple translation
551
- testDefaultValueForSimpleTranslation: function() { with(this) {
552
- actual = I18n.translate("warning", {defaultValue: "Warning!"});
553
- assertEqual("Warning!", actual);
554
- }},
555
-
556
- // Default value with interpolation
557
- testDefaultValueWithInterpolation: function() { with(this) {
558
- actual = I18n.translate("alert", {defaultValue: "Attention! {{message}}", message: "You're out of quota!"});
559
- assertEqual("Attention! You're out of quota!", actual);
560
- }},
561
-
562
- // Default value should not be used when scope exist
563
- testDefaultValueShouldNotBeUsedWhenScopeExist: function() { with(this) {
564
- actual = I18n.translate("hello", {defaultValue: "What's up?"});
565
- assertEqual("Hello World!", actual);
566
- }},
567
-
568
- // Default value for pluralize
569
- testDefaultValueForPluralize: function() { with(this) {
570
- options = {defaultValue: {
571
- none: "No things here!",
572
- one: "There is {{count}} thing here!",
573
- other: "There are {{count}} things here!"
574
- }};
575
-
576
- assertEqual("No things here!", I18n.pluralize(0, "things", options));
577
- assertEqual("There is 1 thing here!", I18n.pluralize(1, "things", options));
578
- assertEqual("There are 5 things here!", I18n.pluralize(5, "things", options));
579
- }},
580
-
581
- // Default value for pluralize should not be used when scope exist
582
- testDefaultValueForPluralizeShouldNotBeUsedWhenScopeExist: function() { with(this) {
583
- options = {defaultValue: {
584
- none: "No things here!",
585
- one: "There is {{count}} thing here!",
586
- other: "There are {{count}} things here!"
587
- }};
588
-
589
- assertEqual("You have no messages", I18n.pluralize(0, "inbox", options));
590
- assertEqual("You have 1 message", I18n.pluralize(1, "inbox", options));
591
- assertEqual("You have 5 messages", I18n.pluralize(5, "inbox", options));
592
- }},
593
-
594
- // Prepare options
595
- testPrepareOptions: function() { with(this) {
596
- options = I18n.prepareOptions(
597
- {name: "Mary Doe"},
598
- {name: "John Doe", role: "user"}
599
- );
600
-
601
- assertEqual("Mary Doe", options["name"]);
602
- assertEqual("user", options["role"]);
603
- }},
604
-
605
- // Prepare options with multiple options
606
- testPrepareOptionsWithMultipleOptions: function() { with(this) {
607
- options = I18n.prepareOptions(
608
- {name: "Mary Doe"},
609
- {name: "John Doe", role: "user"},
610
- {age: 33},
611
- {email: "mary@doe.com", url: "http://marydoe.com"},
612
- {role: "admin", email: "john@doe.com"}
613
- );
614
-
615
- assertEqual("Mary Doe", options["name"]);
616
- assertEqual("user", options["role"]);
617
- assertEqual(33, options["age"]);
618
- assertEqual("mary@doe.com", options["email"]);
619
- assertEqual("http://marydoe.com", options["url"]);
620
- }},
621
-
622
- // Prepare options should return an empty hash when values are null
623
- testPrepareOptionsShouldReturnAnEmptyHashWhenValuesAreNull: function() { with(this) {
624
- assertNotNullOrUndefined(I18n.prepareOptions(null, null));
625
- }},
626
-
627
- // Percentage with defaults
628
- testPercentageWithDefaults: function() { with(this) {
629
- assertEqual("1234.000%", I18n.toPercentage(1234));
630
- }},
631
-
632
- // Percentage with custom options
633
- testPercentageWithCustomOptions: function() { with(this) {
634
- assertEqual("1_234%", I18n.toPercentage(1234, {delimiter: "_", precision: 0}));
635
- }},
636
-
637
- // Percentage with translation
638
- testPercentageWithTranslation: function() { with(this) {
639
- I18n.translations.en.number = {
640
- percentage: {
641
- format: {
642
- precision: 2,
643
- delimiter: ".",
644
- separator: ","
645
- }
646
- }
647
- }
648
-
649
- assertEqual("1.234,00%", I18n.toPercentage(1234));
650
- }},
651
-
652
- // Percentage with translation and custom options
653
- testPercentageWithTranslationAndCustomOptions: function() { with(this) {
654
- I18n.translations.en.number = {
655
- percentage: {
656
- format: {
657
- precision: 2,
658
- delimiter: ".",
659
- separator: ","
660
- }
661
- }
662
- }
663
-
664
- assertEqual("1-234+0000%", I18n.toPercentage(1234, {precision: 4, delimiter: "-", separator: "+"}));
665
- }},
666
-
667
- // Scope option as string
668
- testScopeOptionAsString: function() { with(this) {
669
- actual = I18n.translate("stranger", {scope: "greetings"});
670
- assertEqual("Hello stranger!", actual);
671
- }},
672
-
673
- // Scope as array
674
- testScopeAsArray: function() { with(this) {
675
- actual = I18n.translate(["greetings", "stranger"]);
676
- assertEqual("Hello stranger!", actual);
677
- }},
678
-
679
- // New placeholder syntax
680
- testNewPlaceholderSyntax: function() { with(this) {
681
- I18n.translations["en"]["new_syntax"] = "Hi %{name}!";
682
- actual = I18n.translate("new_syntax", {name: "John"});
683
- assertEqual("Hi John!", actual);
684
- }},
685
-
686
- // Return translation for custom scope separator
687
- testReturnTranslationForCustomScopeSeparator: function() { with(this) {
688
- I18n.defaultSeparator = "•";
689
- actual = I18n.translate("greetings•stranger");
690
- assertEqual("Hello stranger!", actual);
691
- }}
692
- });