i18n-js 3.7.1 → 4.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +4 -0
  3. data/.github/FUNDING.yml +3 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  6. data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
  7. data/.github/dependabot.yml +15 -0
  8. data/.github/workflows/ruby-tests.yml +61 -0
  9. data/.gitignore +11 -7
  10. data/.rubocop.yml +12 -0
  11. data/CHANGELOG.md +12 -495
  12. data/CODE_OF_CONDUCT.md +74 -0
  13. data/CONTRIBUTING.md +79 -0
  14. data/Gemfile +3 -0
  15. data/LICENSE.md +20 -0
  16. data/README.md +89 -903
  17. data/Rakefile +10 -20
  18. data/exe/i18n +5 -0
  19. data/i18n-js.gemspec +47 -29
  20. data/lib/guard/i18n-js.rb +78 -0
  21. data/lib/guard/i18n-js/templates/Guardfile +10 -0
  22. data/lib/guard/i18n-js/version.rb +13 -0
  23. data/lib/i18n-js.rb +66 -1
  24. data/lib/i18n-js/cli.rb +47 -0
  25. data/lib/i18n-js/cli/command.rb +43 -0
  26. data/lib/i18n-js/cli/export_command.rb +108 -0
  27. data/lib/i18n-js/cli/init_command.rb +50 -0
  28. data/lib/i18n-js/cli/ui.rb +30 -0
  29. data/lib/i18n-js/cli/version_command.rb +18 -0
  30. data/lib/i18n-js/listen.rb +80 -0
  31. data/lib/i18n-js/schema.rb +92 -0
  32. data/lib/i18n-js/version.rb +5 -0
  33. metadata +123 -190
  34. data/.editorconfig +0 -24
  35. data/.npmignore +0 -27
  36. data/.travis.yml +0 -39
  37. data/Appraisals +0 -44
  38. data/app/assets/javascripts/i18n.js +0 -1092
  39. data/app/assets/javascripts/i18n/filtered.js.erb +0 -23
  40. data/app/assets/javascripts/i18n/shims.js +0 -240
  41. data/app/assets/javascripts/i18n/translations.js +0 -3
  42. data/gemfiles/i18n_0_6.gemfile +0 -7
  43. data/gemfiles/i18n_0_7.gemfile +0 -7
  44. data/gemfiles/i18n_0_8.gemfile +0 -7
  45. data/gemfiles/i18n_0_9.gemfile +0 -7
  46. data/gemfiles/i18n_1_0.gemfile +0 -7
  47. data/gemfiles/i18n_1_1.gemfile +0 -7
  48. data/gemfiles/i18n_1_2.gemfile +0 -7
  49. data/gemfiles/i18n_1_3.gemfile +0 -7
  50. data/gemfiles/i18n_1_4.gemfile +0 -7
  51. data/gemfiles/i18n_1_5.gemfile +0 -7
  52. data/gemfiles/i18n_1_6.gemfile +0 -7
  53. data/gemfiles/i18n_1_7.gemfile +0 -7
  54. data/gemfiles/i18n_1_8.gemfile +0 -7
  55. data/lib/i18n/js.rb +0 -259
  56. data/lib/i18n/js/dependencies.rb +0 -63
  57. data/lib/i18n/js/engine.rb +0 -87
  58. data/lib/i18n/js/fallback_locales.rb +0 -70
  59. data/lib/i18n/js/formatters/base.rb +0 -25
  60. data/lib/i18n/js/formatters/js.rb +0 -32
  61. data/lib/i18n/js/formatters/json.rb +0 -13
  62. data/lib/i18n/js/middleware.rb +0 -82
  63. data/lib/i18n/js/private/hash_with_symbol_keys.rb +0 -36
  64. data/lib/i18n/js/segment.rb +0 -80
  65. data/lib/i18n/js/utils.rb +0 -78
  66. data/lib/i18n/js/version.rb +0 -7
  67. data/lib/rails/generators/i18n/js/config/config_generator.rb +0 -19
  68. data/lib/rails/generators/i18n/js/config/templates/i18n-js.yml +0 -27
  69. data/lib/tasks/export.rake +0 -8
  70. data/package.json +0 -25
  71. data/spec/fixtures/custom_path.yml +0 -5
  72. data/spec/fixtures/default.yml +0 -5
  73. data/spec/fixtures/erb.yml +0 -5
  74. data/spec/fixtures/except_condition.yml +0 -7
  75. data/spec/fixtures/js_export_dir_custom.yml +0 -7
  76. data/spec/fixtures/js_export_dir_none.yml +0 -6
  77. data/spec/fixtures/js_extend_parent.yml +0 -6
  78. data/spec/fixtures/js_extend_segment.yml +0 -6
  79. data/spec/fixtures/js_file_per_locale.yml +0 -7
  80. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml +0 -4
  81. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml +0 -6
  82. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml +0 -4
  83. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml +0 -4
  84. data/spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml +0 -4
  85. data/spec/fixtures/js_file_per_locale_without_fallbacks.yml +0 -4
  86. data/spec/fixtures/js_file_with_namespace_prefix_and_pretty_print.yml +0 -9
  87. data/spec/fixtures/js_sort_translation_keys_false.yml +0 -6
  88. data/spec/fixtures/js_sort_translation_keys_true.yml +0 -6
  89. data/spec/fixtures/json_only.yml +0 -18
  90. data/spec/fixtures/locales.yml +0 -133
  91. data/spec/fixtures/merge_plurals.yml +0 -6
  92. data/spec/fixtures/merge_plurals_with_no_overrides.yml +0 -4
  93. data/spec/fixtures/merge_plurals_with_partial_overrides.yml +0 -4
  94. data/spec/fixtures/millions.yml +0 -4
  95. data/spec/fixtures/multiple_conditions.yml +0 -7
  96. data/spec/fixtures/multiple_conditions_per_locale.yml +0 -7
  97. data/spec/fixtures/multiple_files.yml +0 -7
  98. data/spec/fixtures/no_config.yml +0 -2
  99. data/spec/fixtures/no_scope.yml +0 -4
  100. data/spec/fixtures/simple_scope.yml +0 -5
  101. data/spec/js/currency.spec.js +0 -62
  102. data/spec/js/current_locale.spec.js +0 -19
  103. data/spec/js/dates.spec.js +0 -276
  104. data/spec/js/defaults.spec.js +0 -31
  105. data/spec/js/extend.spec.js +0 -110
  106. data/spec/js/interpolation.spec.js +0 -124
  107. data/spec/js/jasmine/MIT.LICENSE +0 -20
  108. data/spec/js/jasmine/jasmine-html.js +0 -190
  109. data/spec/js/jasmine/jasmine.css +0 -166
  110. data/spec/js/jasmine/jasmine.js +0 -2476
  111. data/spec/js/jasmine/jasmine_favicon.png +0 -0
  112. data/spec/js/locales.spec.js +0 -31
  113. data/spec/js/localization.spec.js +0 -78
  114. data/spec/js/numbers.spec.js +0 -170
  115. data/spec/js/placeholder.spec.js +0 -24
  116. data/spec/js/pluralization.spec.js +0 -219
  117. data/spec/js/prepare_options.spec.js +0 -41
  118. data/spec/js/require.js +0 -2083
  119. data/spec/js/specs.html +0 -49
  120. data/spec/js/specs_requirejs.html +0 -72
  121. data/spec/js/translate.spec.js +0 -299
  122. data/spec/js/translations.js +0 -172
  123. data/spec/js/utility_functions.spec.js +0 -20
  124. data/spec/ruby/i18n/js/fallback_locales_spec.rb +0 -84
  125. data/spec/ruby/i18n/js/segment_spec.rb +0 -219
  126. data/spec/ruby/i18n/js/utils_spec.rb +0 -106
  127. data/spec/ruby/i18n/js_spec.rb +0 -748
  128. data/spec/spec_helper.rb +0 -79
  129. data/yarn.lock +0 -131
Binary file
@@ -1,31 +0,0 @@
1
- var I18n = require("../../app/assets/javascripts/i18n");
2
-
3
- describe("Locales", function(){
4
- beforeEach(function(){
5
- I18n.reset();
6
- });
7
-
8
- it("returns the requested locale, if available", function(){
9
- I18n.locales["ab"] = ["ab"];
10
- expect(I18n.locales.get("ab")).toEqual(["ab"]);
11
- });
12
-
13
- it("wraps single results in an array", function(){
14
- I18n.locales["cd"] = "cd";
15
- expect(I18n.locales.get("cd")).toEqual(["cd"]);
16
- });
17
-
18
- it("returns the result of locale functions", function(){
19
- I18n.locales["fn"] = function() {
20
- return "gg";
21
- };
22
- expect(I18n.locales.get("fn")).toEqual(["gg"]);
23
- });
24
-
25
- it("uses I18n.locale as a fallback", function(){
26
- I18n.locale = "xx";
27
- I18n.locales["xx"] = ["xx"];
28
- expect(I18n.locales.get()).toEqual(["xx"]);
29
- expect(I18n.locales.get("yy")).toEqual(["xx"]);
30
- });
31
- });
@@ -1,78 +0,0 @@
1
- var I18n = require("../../app/assets/javascripts/i18n")
2
- , Translations = require("./translations")
3
- ;
4
-
5
- describe("Localization", function(){
6
- var actual, expected;
7
-
8
- beforeEach(function() {
9
- I18n.reset();
10
- I18n.translations = Translations();
11
- });
12
-
13
- it("sets bound alias", function() {
14
- expect(I18n.l).toEqual(jasmine.any(Function));
15
- expect(I18n.l).not.toBe(I18n.localize);
16
- });
17
-
18
- it("localizes number", function(){
19
- expect(I18n.localize("number", 1234567)).toEqual("1,234,567.000");
20
- });
21
-
22
- it("localizes number with 'l' shortcut", function(){
23
- var l = I18n.l;
24
- expect(l("number", 1234567)).toEqual("1,234,567.000");
25
- });
26
-
27
- it("localizes currency", function(){
28
- expect(I18n.localize("currency", 1234567)).toEqual("$1,234,567.00");
29
- });
30
-
31
- it("localizes date strings", function(){
32
- I18n.locale = "pt-BR";
33
-
34
- expect(I18n.localize("date.formats.default", "2009-11-29")).toEqual("29/11/2009");
35
- expect(I18n.localize("date.formats.short", "2009-01-07")).toEqual("07 de Janeiro");
36
- expect(I18n.localize("date.formats.long", "2009-01-07")).toEqual("07 de Janeiro de 2009");
37
- });
38
-
39
- it("localizes strings with locale from options", function(){
40
- I18n.locale = "en";
41
-
42
- expect(I18n.localize("date.formats.default", "2009-11-29", { locale: "pt-BR" })).toEqual("29/11/2009");
43
- expect(I18n.localize("date.formats.short", "2009-01-07", { locale: "pt-BR" })).toEqual("07 de Janeiro");
44
- expect(I18n.localize("date.formats.long", "2009-01-07", { locale: "pt-BR" })).toEqual("07 de Janeiro de 2009");
45
- expect(I18n.localize("time.formats.default", "2009-11-29 15:07:59", { locale: "pt-BR" })).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
46
- expect(I18n.localize("time.formats.short", "2009-01-07 09:12:35", { locale: "pt-BR" })).toEqual("07/01, 09:12 h");
47
- expect(I18n.localize("time.formats.long", "2009-11-29 15:07:59", { locale: "pt-BR" })).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
48
- expect(I18n.localize("number", 1234567, { locale: "pt-BR" })).toEqual("1,234,567.000");
49
- expect(I18n.localize("currency", 1234567, { locale: "pt-BR" })).toEqual("R$ 1.234.567,00");
50
- expect(I18n.localize("percentage", 123.45, { locale: "pt-BR" })).toEqual("123,45%");
51
- });
52
-
53
- it("localizes time strings", function(){
54
- I18n.locale = "pt-BR";
55
-
56
- expect(I18n.localize("time.formats.default", "2009-11-29 15:07:59")).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
57
- expect(I18n.localize("time.formats.short", "2009-01-07 09:12:35")).toEqual("07/01, 09:12 h");
58
- expect(I18n.localize("time.formats.long", "2009-11-29 15:07:59")).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
59
- });
60
-
61
- it("return 'Invalid Date' or original value for invalid input", function(){
62
- expect(I18n.localize("time.formats.default", "")).toEqual("Invalid Date");
63
- expect(I18n.localize("time.formats.default", null)).toEqual(null);
64
- expect(I18n.localize("time.formats.default", undefined)).toEqual(undefined);
65
- });
66
-
67
- it("localizes date/time strings with placeholders", function(){
68
- I18n.locale = "pt-BR";
69
-
70
- expect(I18n.localize("date.formats.short_with_placeholders", "2009-01-07", { p1: "!", p2: "?" })).toEqual("07 de Janeiro ! ?");
71
- expect(I18n.localize("time.formats.short_with_placeholders", "2009-01-07 09:12:35", { p1: "!" })).toEqual("07/01, 09:12 h !");
72
- });
73
-
74
- it("localizes percentage", function(){
75
- I18n.locale = "pt-BR";
76
- expect(I18n.localize("percentage", 123.45)).toEqual("123,45%");
77
- });
78
- });
@@ -1,170 +0,0 @@
1
- var I18n = require("../../app/assets/javascripts/i18n")
2
- , Translations = require("./translations")
3
- ;
4
-
5
- describe("Numbers", function(){
6
- var actual, expected;
7
-
8
- beforeEach(function() {
9
- I18n.reset();
10
- I18n.translations = Translations();
11
- });
12
-
13
- it("formats number with default settings", function(){
14
- expect(I18n.toNumber(1)).toEqual("1.000");
15
- expect(I18n.toNumber(12)).toEqual("12.000");
16
- expect(I18n.toNumber(123)).toEqual("123.000");
17
- expect(I18n.toNumber(1234)).toEqual("1,234.000");
18
- expect(I18n.toNumber(12345)).toEqual("12,345.000");
19
- expect(I18n.toNumber(123456)).toEqual("123,456.000");
20
- expect(I18n.toNumber(1234567)).toEqual("1,234,567.000");
21
- expect(I18n.toNumber(12345678)).toEqual("12,345,678.000");
22
- expect(I18n.toNumber(123456789)).toEqual("123,456,789.000");
23
- });
24
-
25
- it("formats negative numbers with default settings", function(){
26
- expect(I18n.toNumber(-1)).toEqual("-1.000");
27
- expect(I18n.toNumber(-12)).toEqual("-12.000");
28
- expect(I18n.toNumber(-123)).toEqual("-123.000");
29
- expect(I18n.toNumber(-1234)).toEqual("-1,234.000");
30
- expect(I18n.toNumber(-12345)).toEqual("-12,345.000");
31
- expect(I18n.toNumber(-123456)).toEqual("-123,456.000");
32
- expect(I18n.toNumber(-1234567)).toEqual("-1,234,567.000");
33
- expect(I18n.toNumber(-12345678)).toEqual("-12,345,678.000");
34
- expect(I18n.toNumber(-123456789)).toEqual("-123,456,789.000");
35
- });
36
-
37
- it("formats number with partial translation and default options", function(){
38
- I18n.translations.en.number = {
39
- format: {
40
- precision: 2
41
- }
42
- };
43
-
44
- expect(I18n.toNumber(1234)).toEqual("1,234.00");
45
- });
46
-
47
- it("formats number with full translation and default options", function(){
48
- I18n.translations.en.number = {
49
- format: {
50
- delimiter: ".",
51
- separator: ",",
52
- precision: 2
53
- }
54
- };
55
-
56
- expect(I18n.toNumber(1234)).toEqual("1.234,00");
57
- });
58
-
59
- it("formats numbers with some custom options that should be merged with default options", function(){
60
- expect(I18n.toNumber(1234.56, {precision: 0})).toEqual("1,235");
61
- expect(I18n.toNumber(1234, {separator: '-'})).toEqual("1,234-000");
62
- expect(I18n.toNumber(1234, {delimiter: '_'})).toEqual("1_234.000");
63
- });
64
-
65
- it("formats number considering options", function(){
66
- options = {
67
- precision: 2,
68
- separator: ",",
69
- delimiter: "."
70
- };
71
-
72
- expect(I18n.toNumber(1, options)).toEqual("1,00");
73
- expect(I18n.toNumber(12, options)).toEqual("12,00");
74
- expect(I18n.toNumber(123, options)).toEqual("123,00");
75
- expect(I18n.toNumber(1234, options)).toEqual("1.234,00");
76
- expect(I18n.toNumber(123456, options)).toEqual("123.456,00");
77
- expect(I18n.toNumber(1234567, options)).toEqual("1.234.567,00");
78
- expect(I18n.toNumber(12345678, options)).toEqual("12.345.678,00");
79
- });
80
-
81
- it("formats numbers with different precisions", function(){
82
- options = {separator: ".", delimiter: ","};
83
-
84
- options["precision"] = 2;
85
- expect(I18n.toNumber(1.98, options)).toEqual("1.98");
86
-
87
- options["precision"] = 3;
88
- expect(I18n.toNumber(1.98, options)).toEqual("1.980");
89
-
90
- options["precision"] = 2;
91
- expect(I18n.toNumber(1.987, options)).toEqual("1.99");
92
-
93
- options["precision"] = 1;
94
- expect(I18n.toNumber(1.98, options)).toEqual("2.0");
95
-
96
- options["precision"] = 0;
97
- expect(I18n.toNumber(1.98, options)).toEqual("2");
98
- });
99
-
100
- it("rounds numbers correctly when precision is given", function(){
101
- options = {separator: ".", delimiter: ","};
102
-
103
- options["precision"] = 2;
104
- expect(I18n.toNumber(0.104, options)).toEqual("0.10");
105
-
106
- options["precision"] = 2;
107
- expect(I18n.toNumber(0.105, options)).toEqual("0.11");
108
-
109
- options["precision"] = 2;
110
- expect(I18n.toNumber(1.005, options)).toEqual("1.01");
111
-
112
- options["precision"] = 3;
113
- expect(I18n.toNumber(35.855, options)).toEqual("35.855");
114
-
115
- options["precision"] = 2;
116
- expect(I18n.toNumber(35.855, options)).toEqual("35.86");
117
-
118
- options["precision"] = 1;
119
- expect(I18n.toNumber(35.855, options)).toEqual("35.9");
120
-
121
- options["precision"] = 0;
122
- expect(I18n.toNumber(35.855, options)).toEqual("36");
123
-
124
- options["precision"] = 0;
125
- expect(I18n.toNumber(0.000000000000001, options)).toEqual("0");
126
- });
127
-
128
- it("returns number as human size", function(){
129
- var kb = 1024;
130
-
131
- expect(I18n.toHumanSize(1)).toEqual("1Byte");
132
- expect(I18n.toHumanSize(100)).toEqual("100Bytes");
133
-
134
- expect(I18n.toHumanSize(kb)).toEqual("1KB");
135
- expect(I18n.toHumanSize(kb * 1.5)).toEqual("1.5KB");
136
-
137
- expect(I18n.toHumanSize(kb * kb)).toEqual("1MB");
138
- expect(I18n.toHumanSize(kb * kb * 1.5)).toEqual("1.5MB");
139
-
140
- expect(I18n.toHumanSize(kb * kb * kb)).toEqual("1GB");
141
- expect(I18n.toHumanSize(kb * kb * kb * 1.5)).toEqual("1.5GB");
142
-
143
- expect(I18n.toHumanSize(kb * kb * kb * kb)).toEqual("1TB");
144
- expect(I18n.toHumanSize(kb * kb * kb * kb * 1.5)).toEqual("1.5TB");
145
-
146
- expect(I18n.toHumanSize(kb * kb * kb * kb * kb)).toEqual("1024TB");
147
- });
148
-
149
- it("returns number as human size using custom options", function(){
150
- expect(I18n.toHumanSize(1024 * 1.6, {precision: 0})).toEqual("2KB");
151
- });
152
-
153
- it("formats numbers with strip insignificant zero", function() {
154
- options = {separator: ".", delimiter: ",", strip_insignificant_zeros: true};
155
-
156
- options["precision"] = 2;
157
- expect(I18n.toNumber(1.0, options)).toEqual("1");
158
-
159
- options["precision"] = 3;
160
- expect(I18n.toNumber(1.98, options)).toEqual("1.98");
161
-
162
- options["precision"] = 4;
163
- expect(I18n.toNumber(1.987, options)).toEqual("1.987");
164
- });
165
-
166
- it("keeps significant zeros [issue#103]", function() {
167
- actual = I18n.toNumber(30, {strip_insignificant_zeros: true, precision: 0});
168
- expect(actual).toEqual("30");
169
- });
170
- });
@@ -1,24 +0,0 @@
1
- var I18n = require("../../app/assets/javascripts/i18n");
2
-
3
- describe("Placeholder", function(){
4
- beforeEach(function(){
5
- I18n.reset();
6
- });
7
-
8
- it("matches {{name}}", function(){
9
- expect("{{name}}").toMatch(I18n.placeholder);
10
- });
11
-
12
- it("matches %{name}", function(){
13
- expect("%{name}").toMatch(I18n.placeholder);
14
- });
15
-
16
- it("returns placeholders", function(){
17
- var translation = "I like %{javascript}. I also like %{ruby}"
18
- , matches = translation.match(I18n.placeholder);
19
- ;
20
-
21
- expect(matches[0]).toEqual("%{javascript}");
22
- expect(matches[1]).toEqual("%{ruby}");
23
- });
24
- });
@@ -1,219 +0,0 @@
1
- var I18n = require("../../app/assets/javascripts/i18n")
2
- , Translations = require("./translations")
3
- ;
4
-
5
- describe("Pluralization", function(){
6
- var actual, expected;
7
-
8
- beforeEach(function(){
9
- I18n.reset();
10
- I18n.translations = Translations();
11
- });
12
-
13
- it("sets bound alias", function() {
14
- expect(I18n.p).toEqual(jasmine.any(Function));
15
- expect(I18n.p).not.toBe(I18n.pluralize);
16
- });
17
-
18
- it("pluralizes scope", function(){
19
- expect(I18n.p(0, "inbox")).toEqual("You have no messages");
20
- expect(I18n.p(1, "inbox")).toEqual("You have 1 message");
21
- expect(I18n.p(5, "inbox")).toEqual("You have 5 messages");
22
- });
23
-
24
- it("pluralizes scope with 'p' shortcut", function(){
25
- var p = I18n.p;
26
- expect(p(0, "inbox")).toEqual("You have no messages");
27
- expect(p(1, "inbox")).toEqual("You have 1 message");
28
- expect(p(5, "inbox")).toEqual("You have 5 messages");
29
- });
30
-
31
- it("pluralizes using the 'other' scope", function(){
32
- I18n.translations["en"]["inbox"]["zero"] = null;
33
- expect(I18n.p(0, "inbox")).toEqual("You have 0 messages");
34
- });
35
-
36
- it("pluralizes using the 'zero' scope", function(){
37
- I18n.translations["en"]["inbox"]["zero"] = "No messages (zero)";
38
-
39
- expect(I18n.p(0, "inbox")).toEqual("No messages (zero)");
40
- });
41
-
42
- it("pluralizes using negative values", function(){
43
- expect(I18n.p(-1, "inbox")).toEqual("You have -1 messages");
44
- expect(I18n.p(-5, "inbox")).toEqual("You have -5 messages");
45
- });
46
-
47
- it("returns missing translation", function(){
48
- expect(I18n.p(-1, "missing")).toEqual('[missing "en.missing" translation]');
49
- });
50
-
51
- it("pluralizes using multiple placeholders", function(){
52
- actual = I18n.p(1, "unread", {unread: 5});
53
- expect(actual).toEqual("You have 1 new message (5 unread)");
54
-
55
- actual = I18n.p(10, "unread", {unread: 2});
56
- expect(actual).toEqual("You have 10 new messages (2 unread)");
57
-
58
- actual = I18n.p(0, "unread", {unread: 5});
59
- expect(actual).toEqual("You have no new messages (5 unread)");
60
- });
61
-
62
- it("allows empty strings", function(){
63
- I18n.translations["en"]["inbox"]["zero"] = "";
64
-
65
- expect(I18n.p(0, "inbox")).toEqual("");
66
- });
67
-
68
- it("returns missing message on null values", function(){
69
- I18n.translations["en"]["sent"]["zero"] = null;
70
- I18n.translations["en"]["sent"]["one"] = null;
71
- I18n.translations["en"]["sent"]["other"] = null;
72
-
73
- expect(I18n.p(0, "sent")).toEqual('[missing "en.sent.zero" translation]');
74
- expect(I18n.p(1, "sent")).toEqual('[missing "en.sent.one" translation]');
75
- expect(I18n.p(5, "sent")).toEqual('[missing "en.sent.other" translation]');
76
- });
77
-
78
- it("pluralizes using custom rules", function() {
79
- I18n.locale = "custom";
80
-
81
- I18n.pluralization["custom"] = function(count) {
82
- if (count === 0) { return ["zero"]; }
83
- if (count >= 1 && count <= 5) { return ["few", "other"]; }
84
- return ["other"];
85
- };
86
-
87
- I18n.translations["custom"] = {
88
- "things": {
89
- "zero": "No things"
90
- , "few": "A few things"
91
- , "other": "%{count} things"
92
- }
93
- }
94
-
95
- expect(I18n.p(0, "things")).toEqual("No things");
96
- expect(I18n.p(4, "things")).toEqual("A few things");
97
- expect(I18n.p(-4, "things")).toEqual("-4 things");
98
- expect(I18n.p(10, "things")).toEqual("10 things");
99
- });
100
-
101
- it("pluralizes default value", function(){
102
- options = {defaultValue: {
103
- zero: "No things here!"
104
- , one: "There is {{count}} thing here!"
105
- , other: "There are {{count}} things here!"
106
- }};
107
-
108
- expect(I18n.p(0, "things", options)).toEqual("No things here!");
109
- expect(I18n.p(1, "things", options)).toEqual("There is 1 thing here!");
110
- expect(I18n.p(5, "things", options)).toEqual("There are 5 things here!");
111
- });
112
-
113
- it("ignores pluralization when scope exists", function(){
114
- options = {defaultValue: {
115
- zero: "No things here!"
116
- , one: "There is {{count}} thing here!"
117
- , other: "There are {{count}} things here!"
118
- }};
119
-
120
- expect(I18n.p(0, "inbox", options)).toEqual("You have no messages");
121
- expect(I18n.p(1, "inbox", options)).toEqual("You have 1 message");
122
- expect(I18n.p(5, "inbox", options)).toEqual("You have 5 messages");
123
- });
124
-
125
- it("fallback to default locale when I18n.fallbacks is enabled", function() {
126
- I18n.locale = "pt-BR";
127
- I18n.fallbacks = true;
128
- I18n.translations["pt-BR"].inbox= {
129
- one: null
130
- , other: null
131
- , zero: null
132
- };
133
- expect(I18n.p(0, "inbox", { count: 0 })).toEqual("You have no messages");
134
- expect(I18n.p(1, "inbox", { count: 1 })).toEqual("You have 1 message");
135
- expect(I18n.p(5, "inbox", { count: 5 })).toEqual("You have 5 messages");
136
- });
137
-
138
- it("fallback to default locale when I18n.fallbacks is enabled", function() {
139
- I18n.locale = "pt-BR";
140
- I18n.fallbacks = true;
141
- I18n.translations["pt-BR"].inbox= {
142
- one: "Você tem uma mensagem"
143
- , other: null
144
- , zero: "Você não tem nenhuma mensagem"
145
- };
146
- expect(I18n.p(0, "inbox", { count: 0 })).toEqual("Você não tem nenhuma mensagem");
147
- expect(I18n.p(1, "inbox", { count: 1 })).toEqual("Você tem uma mensagem");
148
- expect(I18n.p(5, "inbox", { count: 5 })).toEqual('You have 5 messages');
149
- });
150
-
151
- it("fallback to 'other' scope", function() {
152
- I18n.locale = "pt-BR";
153
- I18n.fallbacks = true;
154
- I18n.translations["pt-BR"].inbox= {
155
- one: "Você tem uma mensagem"
156
- , other: "Você tem {{count}} mensagens"
157
- , zero: null
158
- }
159
- expect(I18n.p(0, "inbox", { count: 0 })).toEqual("Você tem 0 mensagens");
160
- expect(I18n.p(1, "inbox", { count: 1 })).toEqual("Você tem uma mensagem");
161
- expect(I18n.p(5, "inbox", { count: 5 })).toEqual("Você tem 5 mensagens");
162
- });
163
-
164
- it("fallback to defaulValue when defaultValue is string", function() {
165
- I18n.locale = "pt-BR";
166
- I18n.fallbacks = true;
167
- I18n.translations["en"]["inbox"]["zero"] = null;
168
- I18n.translations["en"]["inbox"]["one"] = null;
169
- I18n.translations["en"]["inbox"]["other"] = null;
170
- I18n.translations["pt-BR"].inbox= {
171
- one: "Você tem uma mensagem"
172
- , other: null
173
- , zero: null
174
- }
175
- options = {
176
- defaultValue: "default message"
177
- };
178
- expect(I18n.p(0, "inbox", options)).toEqual("default message");
179
- expect(I18n.p(1, "inbox", options)).toEqual("Você tem uma mensagem");
180
- expect(I18n.p(5, "inbox", options)).toEqual("default message");
181
- });
182
-
183
- it("fallback to defaulValue when defaultValue is an object", function() {
184
- I18n.locale = "pt-BR";
185
- I18n.fallbacks = true;
186
- I18n.translations["en"]["inbox"]["zero"] = null;
187
- I18n.translations["en"]["inbox"]["one"] = null;
188
- I18n.translations["en"]["inbox"]["other"] = null;
189
- I18n.translations["pt-BR"].inbox= {
190
- one: "Você tem uma mensagem"
191
- , other: null
192
- , zero: null
193
- }
194
- options = {
195
- defaultValue: {
196
- zero: "default message for no message"
197
- , one: "default message for 1 message"
198
- , other: "default message for {{count}} messages"
199
- }
200
- };
201
- expect(I18n.p(0, "inbox", options)).toEqual("default message for no message");
202
- expect(I18n.p(1, "inbox", options)).toEqual("Você tem uma mensagem");
203
- expect(I18n.p(5, "inbox", options)).toEqual("default message for 5 messages");
204
- });
205
-
206
- it("fallback to default locale when I18n.fallbacks is enabled and no translations in sub scope", function() {
207
- I18n.locale = "pt-BR";
208
- I18n.fallbacks = true;
209
- I18n.translations["en"]["mailbox"] = {
210
- inbox: I18n.translations["en"].inbox
211
- }
212
-
213
- expect(I18n.translations["pt-BR"]["mailbox"]).toEqual(undefined);
214
- expect(I18n.p(0, "mailbox.inbox", { count: 0 })).toEqual("You have no messages");
215
- expect(I18n.p(1, "mailbox.inbox", { count: 1 })).toEqual("You have 1 message");
216
- expect(I18n.p(5, "mailbox.inbox", { count: 5 })).toEqual("You have 5 messages");
217
- });
218
-
219
- });