i18n-js 0.1.5 → 0.1.6

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