i18n-js 2.1.2 → 3.0.11

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.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +24 -0
  3. data/.gitignore +5 -4
  4. data/.npmignore +27 -0
  5. data/.travis.yml +37 -0
  6. data/Appraisals +20 -0
  7. data/CHANGELOG.md +354 -0
  8. data/Gemfile +1 -1
  9. data/README.md +872 -0
  10. data/Rakefile +19 -7
  11. data/app/assets/javascripts/i18n/filtered.js.erb +23 -0
  12. data/app/assets/javascripts/i18n/shims.js +208 -0
  13. data/app/assets/javascripts/i18n/translations.js +3 -0
  14. data/app/assets/javascripts/i18n.js +1077 -0
  15. data/gemfiles/i18n_0_6.gemfile +7 -0
  16. data/gemfiles/i18n_0_7.gemfile +7 -0
  17. data/gemfiles/i18n_0_8.gemfile +7 -0
  18. data/gemfiles/i18n_0_9.gemfile +7 -0
  19. data/gemfiles/i18n_1_0.gemfile +7 -0
  20. data/i18n-js.gemspec +11 -9
  21. data/lib/i18n/js/dependencies.rb +59 -0
  22. data/lib/i18n/js/engine.rb +87 -0
  23. data/lib/i18n/js/fallback_locales.rb +70 -0
  24. data/lib/{i18n-js → i18n/js}/middleware.rb +32 -9
  25. data/lib/i18n/js/private/hash_with_symbol_keys.rb +36 -0
  26. data/lib/i18n/js/segment.rb +88 -0
  27. data/lib/i18n/js/utils.rb +52 -0
  28. data/lib/i18n/js/version.rb +7 -0
  29. data/lib/i18n/js.rb +242 -0
  30. data/lib/i18n-js.rb +1 -177
  31. data/lib/rails/generators/i18n/js/config/config_generator.rb +19 -0
  32. data/{config → lib/rails/generators/i18n/js/config/templates}/i18n-js.yml +11 -6
  33. data/lib/tasks/export.rake +8 -0
  34. data/package.json +25 -0
  35. data/spec/fixtures/custom_path.yml +5 -0
  36. data/spec/fixtures/default.yml +5 -0
  37. data/spec/fixtures/erb.yml +5 -0
  38. data/spec/fixtures/except_condition.yml +7 -0
  39. data/spec/fixtures/js_export_dir_custom.yml +7 -0
  40. data/spec/fixtures/js_export_dir_none.yml +6 -0
  41. data/spec/fixtures/js_extend_parent.yml +6 -0
  42. data/spec/fixtures/js_extend_segment.yml +6 -0
  43. data/spec/fixtures/js_file_per_locale.yml +7 -0
  44. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml +4 -0
  45. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml +6 -0
  46. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml +4 -0
  47. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml +4 -0
  48. data/spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml +4 -0
  49. data/spec/fixtures/js_file_per_locale_without_fallbacks.yml +4 -0
  50. data/spec/fixtures/js_file_with_namespace_and_pretty_print.yml +7 -0
  51. data/spec/fixtures/js_sort_translation_keys_false.yml +6 -0
  52. data/spec/fixtures/js_sort_translation_keys_true.yml +6 -0
  53. data/spec/{resources → fixtures}/locales.yml +13 -1
  54. data/spec/fixtures/multiple_conditions.yml +7 -0
  55. data/spec/fixtures/multiple_conditions_per_locale.yml +7 -0
  56. data/spec/fixtures/multiple_files.yml +7 -0
  57. data/spec/{resources → fixtures}/no_config.yml +0 -0
  58. data/spec/fixtures/no_scope.yml +4 -0
  59. data/spec/fixtures/simple_scope.yml +5 -0
  60. data/spec/js/currency.spec.js +62 -0
  61. data/spec/js/current_locale.spec.js +19 -0
  62. data/spec/js/dates.spec.js +265 -0
  63. data/spec/js/defaults.spec.js +31 -0
  64. data/spec/js/extend.spec.js +110 -0
  65. data/spec/js/interpolation.spec.js +124 -0
  66. data/spec/js/jasmine/MIT.LICENSE +20 -0
  67. data/spec/js/jasmine/jasmine-html.js +190 -0
  68. data/spec/js/jasmine/jasmine.css +166 -0
  69. data/spec/js/jasmine/jasmine.js +2476 -0
  70. data/spec/js/jasmine/jasmine_favicon.png +0 -0
  71. data/spec/js/locales.spec.js +31 -0
  72. data/spec/js/localization.spec.js +48 -0
  73. data/spec/js/numbers.spec.js +170 -0
  74. data/spec/js/placeholder.spec.js +24 -0
  75. data/spec/js/pluralization.spec.js +211 -0
  76. data/spec/js/prepare_options.spec.js +41 -0
  77. data/spec/js/require.js +2083 -0
  78. data/spec/js/specs.html +49 -0
  79. data/spec/js/specs_requirejs.html +72 -0
  80. data/spec/js/translate.spec.js +277 -0
  81. data/spec/js/translations.js +164 -0
  82. data/spec/js/utility_functions.spec.js +20 -0
  83. data/spec/ruby/i18n/js/fallback_locales_spec.rb +84 -0
  84. data/spec/ruby/i18n/js/segment_spec.rb +157 -0
  85. data/spec/ruby/i18n/js/utils_spec.rb +106 -0
  86. data/spec/ruby/i18n/js_spec.rb +627 -0
  87. data/spec/spec_helper.rb +55 -14
  88. data/yarn.lock +131 -0
  89. metadata +188 -96
  90. data/.rspec +0 -1
  91. data/Gemfile.lock +0 -51
  92. data/README.rdoc +0 -305
  93. data/lib/i18n-js/engine.rb +0 -62
  94. data/lib/i18n-js/railtie.rb +0 -13
  95. data/lib/i18n-js/rake.rb +0 -16
  96. data/lib/i18n-js/version.rb +0 -10
  97. data/spec/i18n_spec.js +0 -768
  98. data/spec/i18n_spec.rb +0 -205
  99. data/spec/resources/custom_path.yml +0 -4
  100. data/spec/resources/default.yml +0 -4
  101. data/spec/resources/js_file_per_locale.yml +0 -3
  102. data/spec/resources/multiple_conditions.yml +0 -6
  103. data/spec/resources/multiple_files.yml +0 -6
  104. data/spec/resources/no_scope.yml +0 -3
  105. data/spec/resources/simple_scope.yml +0 -4
  106. data/vendor/assets/javascripts/i18n/translations.js.erb +0 -7
  107. data/vendor/assets/javascripts/i18n.js +0 -450
data/spec/i18n_spec.js DELETED
@@ -1,768 +0,0 @@
1
- load("vendor/assets/javascripts/i18n.js");
2
-
3
- describe("I18n.js", function(){
4
- before(function() {
5
- I18n.defaultLocale = "en";
6
- I18n.defaultSeparator = ".";
7
- I18n.locale = null;
8
-
9
- I18n.translations = {
10
- en: {
11
- hello: "Hello World!",
12
- greetings: {
13
- stranger: "Hello stranger!",
14
- name: "Hello {{name}}!"
15
- },
16
- profile: {
17
- details: "{{name}} is {{age}}-years old"
18
- },
19
- inbox: {
20
- one: "You have {{count}} message",
21
- other: "You have {{count}} messages",
22
- zero: "You have no messages"
23
- },
24
- unread: {
25
- one: "You have 1 new message ({{unread}} unread)",
26
- other: "You have {{count}} new messages ({{unread}} unread)",
27
- zero: "You have no new messages ({{unread}} unread)"
28
- },
29
- number: {
30
- human: {
31
- storage_units: {
32
- units: {
33
- "byte": {
34
- one: "Byte",
35
- other: "Bytes"
36
- },
37
-
38
- "kb": "KB",
39
- "mb": "MB",
40
- "gb": "GB",
41
- "tb": "TB"
42
- }
43
- }
44
- }
45
- }
46
- },
47
-
48
- "pt-BR": {
49
- hello: "Olá Mundo!",
50
- date: {
51
- formats: {
52
- "default": "%d/%m/%Y",
53
- "short": "%d de %B",
54
- "long": "%d de %B de %Y"
55
- },
56
- day_names: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"],
57
- abbr_day_names: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"],
58
- month_names: [null, "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
59
- abbr_month_names: [null, "Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]
60
- },
61
- number: {
62
- percentage: {
63
- format: {
64
- delimiter: "",
65
- separator: ",",
66
- precision: 2
67
- }
68
- }
69
- },
70
- time: {
71
- formats: {
72
- "default": "%A, %d de %B de %Y, %H:%M h",
73
- "short": "%d/%m, %H:%M h",
74
- "long": "%A, %d de %B de %Y, %H:%M h"
75
- },
76
- am: "AM",
77
- pm: "PM"
78
- }
79
- },
80
-
81
- "en-US": {
82
- date: {
83
- formats: {
84
- "default": "%d/%m/%Y",
85
- "short": "%d de %B",
86
- "long": "%d de %B de %Y"
87
- },
88
- day_names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
89
- abbr_day_names: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
90
- month_names: [null, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
91
- abbr_month_names: [null, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"],
92
- meridian: ["am", "pm"]
93
- }
94
- }
95
- };
96
- });
97
-
98
- specify("with default options", function(){
99
- expect(I18n.defaultLocale).toBeEqualTo("en");
100
- expect(I18n.locale).toBeEqualTo(null);
101
- expect(I18n.currentLocale()).toBeEqualTo("en");
102
- });
103
-
104
- specify("with custom locale", function(){
105
- I18n.locale = "pt-BR";
106
- expect(I18n.currentLocale()).toBeEqualTo("pt-BR");
107
- });
108
-
109
- specify("aliases", function(){
110
- expect(I18n.t).toBe(I18n.translate);
111
- expect(I18n.l).toBe(I18n.localize);
112
- expect(I18n.p).toBe(I18n.pluralize);
113
- });
114
-
115
- specify("translation with single scope", function(){
116
- expect(I18n.t("hello")).toBeEqualTo("Hello World!");
117
- });
118
-
119
- specify("translation as object", function(){
120
- expect(I18n.t("greetings")).toBeInstanceOf(Object);
121
- });
122
-
123
- specify("translation with invalid scope shall not block", function(){
124
- actual = I18n.t("invalid.scope.shall.not.block");
125
- expected = '[missing "en.invalid.scope.shall.not.block" translation]';
126
- expect(actual).toBeEqualTo(expected);
127
- });
128
-
129
- specify("translation for single scope on a custom locale", function(){
130
- I18n.locale = "pt-BR";
131
- expect(I18n.t("hello")).toBeEqualTo("Olá Mundo!");
132
- });
133
-
134
- specify("translation for multiple scopes", function(){
135
- expect(I18n.t("greetings.stranger")).toBeEqualTo("Hello stranger!");
136
- });
137
-
138
- specify("translation with default locale option", function(){
139
- expect(I18n.t("hello", {locale: "en"})).toBeEqualTo("Hello World!");
140
- expect(I18n.t("hello", {locale: "pt-BR"})).toBeEqualTo("Olá Mundo!");
141
- });
142
-
143
- specify("translation should fall if locale is missing", function(){
144
- I18n.locale = "pt-BR";
145
- expect(I18n.t("greetings.stranger")).toBeEqualTo("[missing \"pt-BR.greetings.stranger\" translation]");
146
- });
147
-
148
- specify("translation should handle fallback if I18n.fallbacks == true", function(){
149
- I18n.locale = "pt-BR";
150
- I18n.fallbacks = true;
151
- expect(I18n.t("greetings.stranger")).toBeEqualTo("Hello stranger!");
152
- });
153
-
154
- specify("single interpolation", function(){
155
- actual = I18n.t("greetings.name", {name: "John Doe"});
156
- expect(actual).toBeEqualTo("Hello John Doe!");
157
- });
158
-
159
- specify("multiple interpolation", function(){
160
- actual = I18n.t("profile.details", {name: "John Doe", age: 27});
161
- expect(actual).toBeEqualTo("John Doe is 27-years old");
162
- });
163
-
164
- specify("translation with count option", function(){
165
- expect(I18n.t("inbox", {count: 0})).toBeEqualTo("You have no messages");
166
- expect(I18n.t("inbox", {count: 1})).toBeEqualTo("You have 1 message");
167
- expect(I18n.t("inbox", {count: 5})).toBeEqualTo("You have 5 messages");
168
- });
169
-
170
- specify("translation with count option and multiple placeholders", function(){
171
- actual = I18n.t("unread", {unread: 5, count: 1});
172
- expect(actual).toBeEqualTo("You have 1 new message (5 unread)");
173
-
174
- actual = I18n.t("unread", {unread: 2, count: 10});
175
- expect(actual).toBeEqualTo("You have 10 new messages (2 unread)");
176
-
177
- actual = I18n.t("unread", {unread: 5, count: 0});
178
- expect(actual).toBeEqualTo("You have no new messages (5 unread)");
179
- });
180
-
181
- specify("missing translation with count option", function(){
182
- actual = I18n.t("invalid", {count: 1});
183
- expect(actual).toBeEqualTo('[missing "en.invalid" translation]');
184
-
185
- I18n.translations.en.inbox.one = null;
186
- actual = I18n.t("inbox", {count: 1});
187
- expect(actual).toBeEqualTo('[missing "en.inbox.one" translation]');
188
- });
189
-
190
- specify("pluralization", function(){
191
- expect(I18n.p(0, "inbox")).toBeEqualTo("You have no messages");
192
- expect(I18n.p(1, "inbox")).toBeEqualTo("You have 1 message");
193
- expect(I18n.p(5, "inbox")).toBeEqualTo("You have 5 messages");
194
- });
195
-
196
- specify("pluralize should return 'other' scope", function(){
197
- I18n.translations["en"]["inbox"]["zero"] = null;
198
- expect(I18n.p(0, "inbox")).toBeEqualTo("You have 0 messages");
199
- });
200
-
201
- specify("pluralize should return 'zero' scope", function(){
202
- I18n.translations["en"]["inbox"]["zero"] = "No messages (zero)";
203
- I18n.translations["en"]["inbox"]["none"] = "No messages (none)";
204
-
205
- expect(I18n.p(0, "inbox")).toBeEqualTo("No messages (zero)");
206
- });
207
-
208
- specify("pluralize should return 'none' scope", function(){
209
- I18n.translations["en"]["inbox"]["zero"] = null;
210
- I18n.translations["en"]["inbox"]["none"] = "No messages (none)";
211
-
212
- expect(I18n.p(0, "inbox")).toBeEqualTo("No messages (none)");
213
- });
214
-
215
- specify("pluralize with negative values", function(){
216
- expect(I18n.p(-1, "inbox")).toBeEqualTo("You have -1 message");
217
- expect(I18n.p(-5, "inbox")).toBeEqualTo("You have -5 messages");
218
- });
219
-
220
- specify("pluralize with missing scope", function(){
221
- expect(I18n.p(-1, "missing")).toBeEqualTo('[missing "en.missing" translation]');
222
- });
223
-
224
- specify("pluralize with multiple placeholders", function(){
225
- actual = I18n.p(1, "unread", {unread: 5});
226
- expect(actual).toBeEqualTo("You have 1 new message (5 unread)");
227
-
228
- actual = I18n.p(10, "unread", {unread: 2});
229
- expect(actual).toBeEqualTo("You have 10 new messages (2 unread)");
230
-
231
- actual = I18n.p(0, "unread", {unread: 5});
232
- expect(actual).toBeEqualTo("You have no new messages (5 unread)");
233
- });
234
-
235
- specify("pluralize should allow empty strings", function(){
236
- I18n.translations["en"]["inbox"]["zero"] = "";
237
-
238
- expect(I18n.p(0, "inbox")).toBeEqualTo("");
239
- });
240
-
241
- specify("numbers with default settings", function(){
242
- expect(I18n.toNumber(1)).toBeEqualTo("1.000");
243
- expect(I18n.toNumber(12)).toBeEqualTo("12.000");
244
- expect(I18n.toNumber(123)).toBeEqualTo("123.000");
245
- expect(I18n.toNumber(1234)).toBeEqualTo("1,234.000");
246
- expect(I18n.toNumber(12345)).toBeEqualTo("12,345.000");
247
- expect(I18n.toNumber(123456)).toBeEqualTo("123,456.000");
248
- expect(I18n.toNumber(1234567)).toBeEqualTo("1,234,567.000");
249
- expect(I18n.toNumber(12345678)).toBeEqualTo("12,345,678.000");
250
- expect(I18n.toNumber(123456789)).toBeEqualTo("123,456,789.000");
251
- });
252
-
253
- specify("negative numbers with default settings", function(){
254
- expect(I18n.toNumber(-1)).toBeEqualTo("-1.000");
255
- expect(I18n.toNumber(-12)).toBeEqualTo("-12.000");
256
- expect(I18n.toNumber(-123)).toBeEqualTo("-123.000");
257
- expect(I18n.toNumber(-1234)).toBeEqualTo("-1,234.000");
258
- expect(I18n.toNumber(-12345)).toBeEqualTo("-12,345.000");
259
- expect(I18n.toNumber(-123456)).toBeEqualTo("-123,456.000");
260
- expect(I18n.toNumber(-1234567)).toBeEqualTo("-1,234,567.000");
261
- expect(I18n.toNumber(-12345678)).toBeEqualTo("-12,345,678.000");
262
- expect(I18n.toNumber(-123456789)).toBeEqualTo("-123,456,789.000");
263
- });
264
-
265
- specify("numbers with partial translation and default options", function(){
266
- I18n.translations.en.number = {
267
- format: {
268
- precision: 2
269
- }
270
- };
271
-
272
- expect(I18n.toNumber(1234)).toBeEqualTo("1,234.00");
273
- });
274
-
275
- specify("numbers with full translation and default options", function(){
276
- I18n.translations.en.number = {
277
- format: {
278
- delimiter: ".",
279
- separator: ",",
280
- precision: 2
281
- }
282
- };
283
-
284
- expect(I18n.toNumber(1234)).toBeEqualTo("1.234,00");
285
- });
286
-
287
- specify("numbers with some custom options that should be merged with default options", function(){
288
- expect(I18n.toNumber(1234, {precision: 0})).toBeEqualTo("1,234");
289
- expect(I18n.toNumber(1234, {separator: '-'})).toBeEqualTo("1,234-000");
290
- expect(I18n.toNumber(1234, {delimiter: '-'})).toBeEqualTo("1-234.000");
291
- });
292
-
293
- specify("numbers considering options", function(){
294
- options = {
295
- precision: 2,
296
- separator: ",",
297
- delimiter: "."
298
- };
299
-
300
- expect(I18n.toNumber(1, options)).toBeEqualTo("1,00");
301
- expect(I18n.toNumber(12, options)).toBeEqualTo("12,00");
302
- expect(I18n.toNumber(123, options)).toBeEqualTo("123,00");
303
- expect(I18n.toNumber(1234, options)).toBeEqualTo("1.234,00");
304
- expect(I18n.toNumber(123456, options)).toBeEqualTo("123.456,00");
305
- expect(I18n.toNumber(1234567, options)).toBeEqualTo("1.234.567,00");
306
- expect(I18n.toNumber(12345678, options)).toBeEqualTo("12.345.678,00");
307
- });
308
-
309
- specify("numbers with different precisions", function(){
310
- options = {separator: ".", delimiter: ","};
311
-
312
- options["precision"] = 2;
313
- expect(I18n.toNumber(1.98, options)).toBeEqualTo("1.98");
314
-
315
- options["precision"] = 3;
316
- expect(I18n.toNumber(1.98, options)).toBeEqualTo("1.980");
317
-
318
- options["precision"] = 2;
319
- expect(I18n.toNumber(1.987, options)).toBeEqualTo("1.99");
320
-
321
- options["precision"] = 1;
322
- expect(I18n.toNumber(1.98, options)).toBeEqualTo("2.0");
323
-
324
- options["precision"] = 0;
325
- expect(I18n.toNumber(1.98, options)).toBeEqualTo("2");
326
- });
327
-
328
- specify("currency with default settings", function(){
329
- expect(I18n.toCurrency(100.99)).toBeEqualTo("$100.99");
330
- expect(I18n.toCurrency(1000.99)).toBeEqualTo("$1,000.99");
331
- });
332
-
333
- specify("currency with custom settings", function(){
334
- I18n.translations.en.number = {
335
- currency: {
336
- format: {
337
- format: "%n %u",
338
- unit: "USD",
339
- delimiter: ".",
340
- separator: ",",
341
- precision: 2
342
- }
343
- }
344
- };
345
-
346
- expect(I18n.toCurrency(12)).toBeEqualTo("12,00 USD");
347
- expect(I18n.toCurrency(123)).toBeEqualTo("123,00 USD");
348
- expect(I18n.toCurrency(1234.56)).toBeEqualTo("1.234,56 USD");
349
- });
350
-
351
- specify("currency with custom settings and partial overriding", function(){
352
- I18n.translations.en.number = {
353
- currency: {
354
- format: {
355
- format: "%n %u",
356
- unit: "USD",
357
- delimiter: ".",
358
- separator: ",",
359
- precision: 2
360
- }
361
- }
362
- };
363
-
364
- expect(I18n.toCurrency(12, {precision: 0})).toBeEqualTo("12 USD");
365
- expect(I18n.toCurrency(123, {unit: "bucks"})).toBeEqualTo("123,00 bucks");
366
- });
367
-
368
- specify("currency with some custom options that should be merged with default options", function(){
369
- expect(I18n.toCurrency(1234, {precision: 0})).toBeEqualTo("$1,234");
370
- expect(I18n.toCurrency(1234, {unit: "º"})).toBeEqualTo("º1,234.00");
371
- expect(I18n.toCurrency(1234, {separator: "-"})).toBeEqualTo("$1,234-00");
372
- expect(I18n.toCurrency(1234, {delimiter: "-"})).toBeEqualTo("$1-234.00");
373
- expect(I18n.toCurrency(1234, {format: "%u %n"})).toBeEqualTo("$ 1,234.00");
374
- });
375
-
376
- specify("localize numbers", function(){
377
- expect(I18n.l("number", 1234567)).toBeEqualTo("1,234,567.000");
378
- });
379
-
380
- specify("localize currency", function(){
381
- expect(I18n.l("currency", 1234567)).toBeEqualTo("$1,234,567.00");
382
- });
383
-
384
- specify("parse date", function(){
385
- expected = new Date(2009, 0, 24, 0, 0, 0);
386
- actual = I18n.parseDate("2009-01-24");
387
- expect(actual.toString()).toBeEqualTo(expected.toString());
388
-
389
- expected = new Date(2009, 0, 24, 0, 15, 0);
390
- actual = I18n.parseDate("2009-01-24 00:15:00");
391
- expect(actual.toString()).toBeEqualTo(expected.toString());
392
-
393
- expected = new Date(2009, 0, 24, 0, 0, 15);
394
- actual = I18n.parseDate("2009-01-24 00:00:15");
395
- expect(actual.toString()).toBeEqualTo(expected.toString());
396
-
397
- expected = new Date(2009, 0, 24, 15, 33, 44);
398
- actual = I18n.parseDate("2009-01-24 15:33:44");
399
- expect(actual.toString()).toBeEqualTo(expected.toString());
400
-
401
- expected = new Date(2009, 0, 24, 0, 0, 0);
402
- actual = I18n.parseDate(expected.getTime());
403
- expect(actual.toString()).toBeEqualTo(expected.toString());
404
-
405
- expected = new Date(2009, 0, 24, 0, 0, 0);
406
- actual = I18n.parseDate("01/24/2009");
407
- expect(actual.toString()).toBeEqualTo(expected.toString());
408
-
409
- expected = new Date(2009, 0, 24, 14, 33, 55);
410
- actual = I18n.parseDate(expected).toString();
411
- expect(actual).toBeEqualTo(expected.toString());
412
-
413
- expected = new Date(2009, 0, 24, 15, 33, 44);
414
- actual = I18n.parseDate("2009-01-24T15:33:44");
415
- expect(actual.toString()).toBeEqualTo(expected.toString());
416
-
417
- expected = new Date(Date.UTC(2011, 6, 20, 12, 51, 55));
418
- actual = I18n.parseDate("2011-07-20T12:51:55+0000");
419
- expect(actual.toString()).toBeEqualTo(expected.toString());
420
-
421
- expected = new Date(Date.UTC(2011, 6, 20, 13, 03, 39));
422
- actual = I18n.parseDate("Wed Jul 20 13:03:39 +0000 2011");
423
- expect(actual.toString()).toBeEqualTo(expected.toString());
424
-
425
- expected = new Date(Date.UTC(2009, 0, 24, 15, 33, 44));
426
- actual = I18n.parseDate("2009-01-24T15:33:44Z");
427
- expect(actual.toString()).toBeEqualTo(expected.toString());
428
- });
429
-
430
- specify("date formatting", function(){
431
- I18n.locale = "pt-BR";
432
-
433
- // 2009-04-26 19:35:44 (Sunday)
434
- var date = new Date(2009, 3, 26, 19, 35, 44);
435
-
436
- // short week day
437
- expect(I18n.strftime(date, "%a")).toBeEqualTo("Dom");
438
-
439
- // full week day
440
- expect(I18n.strftime(date, "%A")).toBeEqualTo("Domingo");
441
-
442
- // short month
443
- expect(I18n.strftime(date, "%b")).toBeEqualTo("Abr");
444
-
445
- // full month
446
- expect(I18n.strftime(date, "%B")).toBeEqualTo("Abril");
447
-
448
- // day
449
- expect(I18n.strftime(date, "%d")).toBeEqualTo("26");
450
-
451
- // 24-hour
452
- expect(I18n.strftime(date, "%H")).toBeEqualTo("19");
453
-
454
- // 12-hour
455
- expect(I18n.strftime(date, "%I")).toBeEqualTo("07");
456
-
457
- // month
458
- expect(I18n.strftime(date, "%m")).toBeEqualTo("04");
459
-
460
- // minutes
461
- expect(I18n.strftime(date, "%M")).toBeEqualTo("35");
462
-
463
- // meridian
464
- expect(I18n.strftime(date, "%p")).toBeEqualTo("PM");
465
-
466
- // seconds
467
- expect(I18n.strftime(date, "%S")).toBeEqualTo("44");
468
-
469
- // week day
470
- expect(I18n.strftime(date, "%w")).toBeEqualTo("0");
471
-
472
- // short year
473
- expect(I18n.strftime(date, "%y")).toBeEqualTo("09");
474
-
475
- // full year
476
- expect(I18n.strftime(date, "%Y")).toBeEqualTo("2009");
477
- });
478
-
479
- specify("date formatting without padding", function(){
480
- I18n.locale = "pt-BR";
481
-
482
- // 2009-04-26 19:35:44 (Sunday)
483
- var date = new Date(2009, 3, 9, 7, 8, 9);
484
-
485
- // 24-hour without padding
486
- expect(I18n.strftime(date, "%-H")).toBeEqualTo("7");
487
-
488
- // 12-hour without padding
489
- expect(I18n.strftime(date, "%-I")).toBeEqualTo("7");
490
-
491
- // minutes without padding
492
- expect(I18n.strftime(date, "%-M")).toBeEqualTo("8");
493
-
494
- // seconds without padding
495
- expect(I18n.strftime(date, "%-S")).toBeEqualTo("9");
496
-
497
- // short year without padding
498
- expect(I18n.strftime(date, "%-y")).toBeEqualTo("9");
499
-
500
- // month without padding
501
- expect(I18n.strftime(date, "%-m")).toBeEqualTo("4");
502
-
503
- // day without padding
504
- expect(I18n.strftime(date, "%-d")).toBeEqualTo("9");
505
- expect(I18n.strftime(date, "%e")).toBeEqualTo("9");
506
- });
507
-
508
- specify("date formatting with padding", function(){
509
- I18n.locale = "pt-BR";
510
-
511
- // 2009-04-26 19:35:44 (Sunday)
512
- var date = new Date(2009, 3, 9, 7, 8, 9);
513
-
514
- // 24-hour
515
- expect(I18n.strftime(date, "%H")).toBeEqualTo("07");
516
-
517
- // 12-hour
518
- expect(I18n.strftime(date, "%I")).toBeEqualTo("07");
519
-
520
- // minutes
521
- expect(I18n.strftime(date, "%M")).toBeEqualTo("08");
522
-
523
- // seconds
524
- expect(I18n.strftime(date, "%S")).toBeEqualTo("09");
525
-
526
- // short year
527
- expect(I18n.strftime(date, "%y")).toBeEqualTo("09");
528
-
529
- // month
530
- expect(I18n.strftime(date, "%m")).toBeEqualTo("04");
531
-
532
- // day
533
- expect(I18n.strftime(date, "%d")).toBeEqualTo("09");
534
- });
535
-
536
- specify("date formatting with negative time zone", function(){
537
- I18n.locale = "pt-BR";
538
- var date = new Date(2009, 3, 26, 19, 35, 44);
539
- stub(date, "getTimezoneOffset()", 345);
540
-
541
- expect(I18n.strftime(date, "%z")).toMatch(/^(\+|-)[\d]{4}$/);
542
- expect(I18n.strftime(date, "%z")).toBeEqualTo("-0545");
543
- });
544
-
545
- specify("date formatting with positive time zone", function(){
546
- I18n.locale = "pt-BR";
547
- var date = new Date(2009, 3, 26, 19, 35, 44);
548
- stub(date, "getTimezoneOffset()", -345);
549
-
550
- expect(I18n.strftime(date, "%z")).toMatch(/^(\+|-)[\d]{4}$/);
551
- expect(I18n.strftime(date, "%z")).toBeEqualTo("+0545");
552
- });
553
-
554
- specify("date formatting with custom meridian", function(){
555
- I18n.locale = "en-US";
556
- var date = new Date(2009, 3, 26, 19, 35, 44);
557
- expect(I18n.strftime(date, "%p")).toBeEqualTo("pm");
558
- });
559
-
560
- specify("date formatting meridian boundaries", function(){
561
- I18n.locale = "en-US";
562
- var date = new Date(2009, 3, 26, 0, 35, 44);
563
- expect(I18n.strftime(date, "%p")).toBeEqualTo("am");
564
-
565
- date = new Date(2009, 3, 26, 12, 35, 44);
566
- expect(I18n.strftime(date, "%p")).toBeEqualTo("pm");
567
- });
568
-
569
- specify("date formatting hour12 values", function(){
570
- I18n.locale = "pt-BR";
571
- var date = new Date(2009, 3, 26, 19, 35, 44);
572
- expect(I18n.strftime(date, "%I")).toBeEqualTo("07");
573
-
574
- date = new Date(2009, 3, 26, 12, 35, 44);
575
- expect(I18n.strftime(date, "%I")).toBeEqualTo("12");
576
-
577
- date = new Date(2009, 3, 26, 0, 35, 44);
578
- expect(I18n.strftime(date, "%I")).toBeEqualTo("12");
579
- });
580
-
581
- specify("localize date strings", function(){
582
- I18n.locale = "pt-BR";
583
-
584
- expect(I18n.l("date.formats.default", "2009-11-29")).toBeEqualTo("29/11/2009");
585
- expect(I18n.l("date.formats.short", "2009-01-07")).toBeEqualTo("07 de Janeiro");
586
- expect(I18n.l("date.formats.long", "2009-01-07")).toBeEqualTo("07 de Janeiro de 2009");
587
- });
588
-
589
- specify("localize time strings", function(){
590
- I18n.locale = "pt-BR";
591
-
592
- expect(I18n.l("time.formats.default", "2009-11-29 15:07:59")).toBeEqualTo("Domingo, 29 de Novembro de 2009, 15:07 h");
593
- expect(I18n.l("time.formats.short", "2009-01-07 09:12:35")).toBeEqualTo("07/01, 09:12 h");
594
- expect(I18n.l("time.formats.long", "2009-11-29 15:07:59")).toBeEqualTo("Domingo, 29 de Novembro de 2009, 15:07 h");
595
- });
596
-
597
- specify("localize percentage", function(){
598
- I18n.locale = "pt-BR";
599
- expect(I18n.l("percentage", 123.45)).toBeEqualTo("123,45%");
600
- });
601
-
602
- specify("default value for simple translation", function(){
603
- actual = I18n.t("warning", {defaultValue: "Warning!"});
604
- expect(actual).toBeEqualTo("Warning!");
605
- });
606
-
607
- specify("default value with interpolation", function(){
608
- actual = I18n.t(
609
- "alert",
610
- {defaultValue: "Attention! {{message}}", message: "You're out of quota!"}
611
- );
612
-
613
- expect(actual).toBeEqualTo("Attention! You're out of quota!");
614
- });
615
-
616
- specify("default value should not be used when scope exist", function(){
617
- actual = I18n.t("hello", {defaultValue: "What's up?"});
618
- expect(actual).toBeEqualTo("Hello World!");
619
- });
620
-
621
- specify("default value for pluralize", function(){
622
- options = {defaultValue: {
623
- none: "No things here!",
624
- one: "There is {{count}} thing here!",
625
- other: "There are {{count}} things here!"
626
- }};
627
-
628
- expect(I18n.p(0, "things", options)).toBeEqualTo("No things here!");
629
- expect(I18n.p(1, "things", options)).toBeEqualTo("There is 1 thing here!");
630
- expect(I18n.p(5, "things", options)).toBeEqualTo("There are 5 things here!");
631
- });
632
-
633
- specify("default value for pluralize should not be used when scope exist", function(){
634
- options = {defaultValue: {
635
- none: "No things here!",
636
- one: "There is {{count}} thing here!",
637
- other: "There are {{count}} things here!"
638
- }};
639
-
640
- expect(I18n.pluralize(0, "inbox", options)).toBeEqualTo("You have no messages");
641
- expect(I18n.pluralize(1, "inbox", options)).toBeEqualTo("You have 1 message");
642
- expect(I18n.pluralize(5, "inbox", options)).toBeEqualTo("You have 5 messages");
643
- });
644
-
645
- specify("prepare options", function(){
646
- options = I18n.prepareOptions(
647
- {name: "Mary Doe"},
648
- {name: "John Doe", role: "user"}
649
- );
650
-
651
- expect(options["name"]).toBeEqualTo("Mary Doe");
652
- expect(options["role"]).toBeEqualTo("user");
653
- });
654
-
655
- specify("prepare options with multiple options", function(){
656
- options = I18n.prepareOptions(
657
- {name: "Mary Doe"},
658
- {name: "John Doe", role: "user"},
659
- {age: 33},
660
- {email: "mary@doe.com", url: "http://marydoe.com"},
661
- {role: "admin", email: "john@doe.com"}
662
- );
663
-
664
- expect(options["name"]).toBeEqualTo("Mary Doe");
665
- expect(options["role"]).toBeEqualTo("user");
666
- expect(options["age"]).toBeEqualTo(33);
667
- expect(options["email"]).toBeEqualTo("mary@doe.com");
668
- expect(options["url"]).toBeEqualTo("http://marydoe.com");
669
- });
670
-
671
- specify("prepare options should return an empty hash when values are null", function(){
672
- expect({}).toBeEqualTo(I18n.prepareOptions(null, null));
673
- });
674
-
675
- specify("percentage with defaults", function(){
676
- expect(I18n.toPercentage(1234)).toBeEqualTo("1234.000%");
677
- });
678
-
679
- specify("percentage with custom options", function(){
680
- actual = I18n.toPercentage(1234, {delimiter: "_", precision: 0});
681
- expect(actual).toBeEqualTo("1_234%");
682
- });
683
-
684
- specify("percentage with translation", function(){
685
- I18n.translations.en.number = {
686
- percentage: {
687
- format: {
688
- precision: 2,
689
- delimiter: ".",
690
- separator: ","
691
- }
692
- }
693
- };
694
-
695
- expect(I18n.toPercentage(1234)).toBeEqualTo("1.234,00%");
696
- });
697
-
698
- specify("percentage with translation and custom options", function(){
699
- I18n.translations.en.number = {
700
- percentage: {
701
- format: {
702
- precision: 2,
703
- delimiter: ".",
704
- separator: ","
705
- }
706
- }
707
- };
708
-
709
- actual = I18n.toPercentage(1234, {precision: 4, delimiter: "-", separator: "+"});
710
- expect(actual).toBeEqualTo("1-234+0000%");
711
- });
712
-
713
- specify("scope option as string", function(){
714
- actual = I18n.t("stranger", {scope: "greetings"});
715
- expect(actual).toBeEqualTo("Hello stranger!");
716
- });
717
-
718
- specify("scope as array", function(){
719
- actual = I18n.t(["greetings", "stranger"]);
720
- expect(actual).toBeEqualTo("Hello stranger!");
721
- });
722
-
723
- specify("new placeholder syntax", function(){
724
- I18n.translations["en"]["new_syntax"] = "Hi %{name}!";
725
- actual = I18n.t("new_syntax", {name: "John"});
726
- expect(actual).toBeEqualTo("Hi John!");
727
- });
728
-
729
- specify("return translation for custom scope separator", function(){
730
- I18n.defaultSeparator = "•";
731
- actual = I18n.t("greetings•stranger");
732
- expect(actual).toBeEqualTo("Hello stranger!");
733
- });
734
-
735
- specify("return number as human size", function(){
736
- kb = 1024;
737
-
738
- expect(I18n.toHumanSize(1)).toBeEqualTo("1Byte");
739
- expect(I18n.toHumanSize(100)).toBeEqualTo("100Bytes");
740
-
741
- expect(I18n.toHumanSize(kb)).toBeEqualTo("1KB");
742
- expect(I18n.toHumanSize(kb * 1.5)).toBeEqualTo("1.5KB");
743
-
744
- expect(I18n.toHumanSize(kb * kb)).toBeEqualTo("1MB");
745
- expect(I18n.toHumanSize(kb * kb * 1.5)).toBeEqualTo("1.5MB");
746
-
747
- expect(I18n.toHumanSize(kb * kb * kb)).toBeEqualTo("1GB");
748
- expect(I18n.toHumanSize(kb * kb * kb * 1.5)).toBeEqualTo("1.5GB");
749
-
750
- expect(I18n.toHumanSize(kb * kb * kb * kb)).toBeEqualTo("1TB");
751
- expect(I18n.toHumanSize(kb * kb * kb * kb * 1.5)).toBeEqualTo("1.5TB");
752
-
753
- expect(I18n.toHumanSize(kb * kb * kb * kb * kb)).toBeEqualTo("1024TB");
754
- });
755
-
756
- specify("return number as human size using custom options", function(){
757
- expect(I18n.toHumanSize(1024 * 1.6, {precision: 0})).toBeEqualTo("2KB");
758
- });
759
-
760
- specify("return number without insignificant zeros", function(){
761
- options = {precision: 4, strip_insignificant_zeros: true};
762
-
763
- expect(I18n.toNumber(65, options)).toBeEqualTo("65");
764
- expect(I18n.toNumber(1.2, options)).toBeEqualTo("1.2");
765
- expect(I18n.toCurrency(1.2, options)).toBeEqualTo("$1.2");
766
- expect(I18n.toHumanSize(1.2, options)).toBeEqualTo("1.2Bytes");
767
- });
768
- });