i18n-js 3.9.2 → 4.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +4 -0
  3. data/.github/FUNDING.yml +1 -1
  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 -571
  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 +86 -1043
  17. data/Rakefile +10 -20
  18. data/exe/i18n +5 -0
  19. data/i18n-js.gemspec +47 -29
  20. data/lib/guard/i18n-js/templates/Guardfile +10 -0
  21. data/lib/guard/i18n-js/version.rb +13 -0
  22. data/lib/guard/i18n-js.rb +78 -0
  23. data/lib/i18n-js/cli/command.rb +43 -0
  24. data/lib/i18n-js/cli/export_command.rb +108 -0
  25. data/lib/i18n-js/cli/init_command.rb +50 -0
  26. data/lib/i18n-js/cli/ui.rb +30 -0
  27. data/lib/i18n-js/cli/version_command.rb +18 -0
  28. data/lib/i18n-js/cli.rb +47 -0
  29. data/lib/i18n-js/listen.rb +80 -0
  30. data/lib/i18n-js/schema.rb +92 -0
  31. data/lib/i18n-js/version.rb +5 -0
  32. data/lib/i18n-js.rb +66 -1
  33. metadata +125 -201
  34. data/.editorconfig +0 -24
  35. data/.github/workflows/tests.yaml +0 -106
  36. data/.npmignore +0 -27
  37. data/Appraisals +0 -52
  38. data/app/assets/javascripts/i18n/filtered.js.erb +0 -23
  39. data/app/assets/javascripts/i18n/shims.js +0 -240
  40. data/app/assets/javascripts/i18n/translations.js +0 -3
  41. data/app/assets/javascripts/i18n.js +0 -1095
  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_10.gemfile +0 -7
  49. data/gemfiles/i18n_1_2.gemfile +0 -7
  50. data/gemfiles/i18n_1_3.gemfile +0 -7
  51. data/gemfiles/i18n_1_4.gemfile +0 -7
  52. data/gemfiles/i18n_1_5.gemfile +0 -7
  53. data/gemfiles/i18n_1_6.gemfile +0 -7
  54. data/gemfiles/i18n_1_7.gemfile +0 -7
  55. data/gemfiles/i18n_1_8.gemfile +0 -7
  56. data/gemfiles/i18n_1_9.gemfile +0 -7
  57. data/i18njs.png +0 -0
  58. data/lib/i18n/js/dependencies.rb +0 -67
  59. data/lib/i18n/js/engine.rb +0 -87
  60. data/lib/i18n/js/fallback_locales.rb +0 -70
  61. data/lib/i18n/js/formatters/base.rb +0 -25
  62. data/lib/i18n/js/formatters/js.rb +0 -39
  63. data/lib/i18n/js/formatters/json.rb +0 -13
  64. data/lib/i18n/js/middleware.rb +0 -82
  65. data/lib/i18n/js/private/config_store.rb +0 -31
  66. data/lib/i18n/js/private/hash_with_symbol_keys.rb +0 -36
  67. data/lib/i18n/js/segment.rb +0 -81
  68. data/lib/i18n/js/utils.rb +0 -91
  69. data/lib/i18n/js/version.rb +0 -7
  70. data/lib/i18n/js.rb +0 -274
  71. data/lib/rails/generators/i18n/js/config/config_generator.rb +0 -19
  72. data/lib/rails/generators/i18n/js/config/templates/i18n-js.yml +0 -27
  73. data/lib/tasks/export.rake +0 -8
  74. data/package.json +0 -25
  75. data/spec/fixtures/custom_path.yml +0 -5
  76. data/spec/fixtures/default.yml +0 -5
  77. data/spec/fixtures/erb.yml +0 -5
  78. data/spec/fixtures/except_condition.yml +0 -7
  79. data/spec/fixtures/js_available_locales_custom.yml +0 -1
  80. data/spec/fixtures/js_export_dir_custom.yml +0 -7
  81. data/spec/fixtures/js_export_dir_none.yml +0 -6
  82. data/spec/fixtures/js_extend_parent.yml +0 -6
  83. data/spec/fixtures/js_extend_segment.yml +0 -6
  84. data/spec/fixtures/js_file_per_locale.yml +0 -7
  85. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml +0 -4
  86. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml +0 -6
  87. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml +0 -4
  88. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml +0 -4
  89. data/spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml +0 -4
  90. data/spec/fixtures/js_file_per_locale_without_fallbacks.yml +0 -4
  91. data/spec/fixtures/js_file_with_namespace_prefix_and_pretty_print.yml +0 -9
  92. data/spec/fixtures/js_sort_translation_keys_false.yml +0 -6
  93. data/spec/fixtures/js_sort_translation_keys_true.yml +0 -6
  94. data/spec/fixtures/json_only.yml +0 -18
  95. data/spec/fixtures/locales.yml +0 -133
  96. data/spec/fixtures/merge_plurals.yml +0 -6
  97. data/spec/fixtures/merge_plurals_with_no_overrides.yml +0 -4
  98. data/spec/fixtures/merge_plurals_with_partial_overrides.yml +0 -4
  99. data/spec/fixtures/millions.yml +0 -4
  100. data/spec/fixtures/multiple_conditions.yml +0 -7
  101. data/spec/fixtures/multiple_conditions_per_locale.yml +0 -7
  102. data/spec/fixtures/multiple_files.yml +0 -7
  103. data/spec/fixtures/no_config.yml +0 -2
  104. data/spec/fixtures/no_scope.yml +0 -4
  105. data/spec/fixtures/simple_scope.yml +0 -5
  106. data/spec/js/currency.spec.js +0 -62
  107. data/spec/js/current_locale.spec.js +0 -19
  108. data/spec/js/dates.spec.js +0 -276
  109. data/spec/js/defaults.spec.js +0 -31
  110. data/spec/js/extend.spec.js +0 -110
  111. data/spec/js/interpolation.spec.js +0 -124
  112. data/spec/js/jasmine/MIT.LICENSE +0 -20
  113. data/spec/js/jasmine/jasmine-html.js +0 -190
  114. data/spec/js/jasmine/jasmine.css +0 -166
  115. data/spec/js/jasmine/jasmine.js +0 -2476
  116. data/spec/js/jasmine/jasmine_favicon.png +0 -0
  117. data/spec/js/json_parsable.spec.js +0 -14
  118. data/spec/js/locales.spec.js +0 -31
  119. data/spec/js/localization.spec.js +0 -78
  120. data/spec/js/numbers.spec.js +0 -174
  121. data/spec/js/placeholder.spec.js +0 -24
  122. data/spec/js/pluralization.spec.js +0 -228
  123. data/spec/js/prepare_options.spec.js +0 -41
  124. data/spec/js/require.js +0 -2083
  125. data/spec/js/specs.html +0 -49
  126. data/spec/js/specs_requirejs.html +0 -72
  127. data/spec/js/translate.spec.js +0 -304
  128. data/spec/js/translations.js +0 -188
  129. data/spec/js/utility_functions.spec.js +0 -20
  130. data/spec/ruby/i18n/js/fallback_locales_spec.rb +0 -84
  131. data/spec/ruby/i18n/js/segment_spec.rb +0 -286
  132. data/spec/ruby/i18n/js/utils_spec.rb +0 -138
  133. data/spec/ruby/i18n/js_spec.rb +0 -797
  134. data/spec/spec_helper.rb +0 -80
  135. data/yarn.lock +0 -138
Binary file
@@ -1,14 +0,0 @@
1
- describe("JSON.parse", function () {
2
- it('should parse', function () {
3
- expect(JSON.parse('{"a":"Test\'s"}')).toEqual({
4
- a: "Test's"
5
- })
6
-
7
- expect(JSON.parse('{"a":"say \\"hello\\""}')).toEqual({
8
- a: 'say "hello"'
9
- });
10
- expect(JSON.parse('{"double-backslash-in-double-quote":"\\"\\\\\\\\\\""}')).toEqual({
11
- 'double-backslash-in-double-quote': '"\\\\"'
12
- });
13
- })
14
- })
@@ -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,174 +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("returns number as human size using custom scope", function(){
154
- expect(I18n.toHumanSize(1024 * 1024, {scope: "extended"})).toEqual("1Megabyte");
155
- });
156
-
157
- it("formats numbers with strip insignificant zero", function() {
158
- options = {separator: ".", delimiter: ",", strip_insignificant_zeros: true};
159
-
160
- options["precision"] = 2;
161
- expect(I18n.toNumber(1.0, options)).toEqual("1");
162
-
163
- options["precision"] = 3;
164
- expect(I18n.toNumber(1.98, options)).toEqual("1.98");
165
-
166
- options["precision"] = 4;
167
- expect(I18n.toNumber(1.987, options)).toEqual("1.987");
168
- });
169
-
170
- it("keeps significant zeros [issue#103]", function() {
171
- actual = I18n.toNumber(30, {strip_insignificant_zeros: true, precision: 0});
172
- expect(actual).toEqual("30");
173
- });
174
- });
@@ -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,228 +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 default locale when I18n.fallbacks is enabled and value is null", function() {
152
- I18n.locale = "pt-BR";
153
- I18n.fallbacks = true;
154
- I18n.translations["pt-BR"].inbox = null;
155
- expect(I18n.p(0, "inbox", { count: 0 })).toEqual("You have no messages");
156
- expect(I18n.p(1, "inbox", { count: 1 })).toEqual("You have 1 message");
157
- expect(I18n.p(5, "inbox", { count: 5 })).toEqual("You have 5 messages");
158
- });
159
-
160
- it("fallback to 'other' scope", function() {
161
- I18n.locale = "pt-BR";
162
- I18n.fallbacks = true;
163
- I18n.translations["pt-BR"].inbox= {
164
- one: "Você tem uma mensagem"
165
- , other: "Você tem {{count}} mensagens"
166
- , zero: null
167
- }
168
- expect(I18n.p(0, "inbox", { count: 0 })).toEqual("Você tem 0 mensagens");
169
- expect(I18n.p(1, "inbox", { count: 1 })).toEqual("Você tem uma mensagem");
170
- expect(I18n.p(5, "inbox", { count: 5 })).toEqual("Você tem 5 mensagens");
171
- });
172
-
173
- it("fallback to defaulValue when defaultValue is string", function() {
174
- I18n.locale = "pt-BR";
175
- I18n.fallbacks = true;
176
- I18n.translations["en"]["inbox"]["zero"] = null;
177
- I18n.translations["en"]["inbox"]["one"] = null;
178
- I18n.translations["en"]["inbox"]["other"] = null;
179
- I18n.translations["pt-BR"].inbox= {
180
- one: "Você tem uma mensagem"
181
- , other: null
182
- , zero: null
183
- }
184
- options = {
185
- defaultValue: "default message"
186
- };
187
- expect(I18n.p(0, "inbox", options)).toEqual("default message");
188
- expect(I18n.p(1, "inbox", options)).toEqual("Você tem uma mensagem");
189
- expect(I18n.p(5, "inbox", options)).toEqual("default message");
190
- });
191
-
192
- it("fallback to defaulValue when defaultValue is an object", function() {
193
- I18n.locale = "pt-BR";
194
- I18n.fallbacks = true;
195
- I18n.translations["en"]["inbox"]["zero"] = null;
196
- I18n.translations["en"]["inbox"]["one"] = null;
197
- I18n.translations["en"]["inbox"]["other"] = null;
198
- I18n.translations["pt-BR"].inbox= {
199
- one: "Você tem uma mensagem"
200
- , other: null
201
- , zero: null
202
- }
203
- options = {
204
- defaultValue: {
205
- zero: "default message for no message"
206
- , one: "default message for 1 message"
207
- , other: "default message for {{count}} messages"
208
- }
209
- };
210
- expect(I18n.p(0, "inbox", options)).toEqual("default message for no message");
211
- expect(I18n.p(1, "inbox", options)).toEqual("Você tem uma mensagem");
212
- expect(I18n.p(5, "inbox", options)).toEqual("default message for 5 messages");
213
- });
214
-
215
- it("fallback to default locale when I18n.fallbacks is enabled and no translations in sub scope", function() {
216
- I18n.locale = "pt-BR";
217
- I18n.fallbacks = true;
218
- I18n.translations["en"]["mailbox"] = {
219
- inbox: I18n.translations["en"].inbox
220
- }
221
-
222
- expect(I18n.translations["pt-BR"]["mailbox"]).toEqual(undefined);
223
- expect(I18n.p(0, "mailbox.inbox", { count: 0 })).toEqual("You have no messages");
224
- expect(I18n.p(1, "mailbox.inbox", { count: 1 })).toEqual("You have 1 message");
225
- expect(I18n.p(5, "mailbox.inbox", { count: 5 })).toEqual("You have 5 messages");
226
- });
227
-
228
- });
@@ -1,41 +0,0 @@
1
- var I18n = require("../../app/assets/javascripts/i18n");
2
-
3
- describe("Prepare options", function(){
4
- beforeEach(function(){
5
- I18n.reset();
6
- });
7
-
8
- it("merges two objects", function(){
9
- var options = I18n.prepareOptions(
10
- {name: "Mary Doe"},
11
- {name: "John Doe", role: "user"}
12
- );
13
-
14
- expect(options.name).toEqual("Mary Doe");
15
- expect(options.role).toEqual("user");
16
- });
17
-
18
- it("merges multiple objects", function(){
19
- var options = I18n.prepareOptions(
20
- {name: "Mary Doe"},
21
- {name: "John Doe", role: "user"},
22
- {age: 33},
23
- {email: "mary@doe.com", url: "http://marydoe.com"},
24
- {role: "admin", email: "john@doe.com"}
25
- );
26
-
27
- expect(options.name).toEqual("Mary Doe");
28
- expect(options.role).toEqual("user");
29
- expect(options.age).toEqual(33);
30
- expect(options.email).toEqual("mary@doe.com");
31
- expect(options.url).toEqual("http://marydoe.com");
32
- });
33
-
34
- it("returns an empty object when values are null", function(){
35
- expect(I18n.prepareOptions(null, null)).toEqual({});
36
- });
37
-
38
- it("returns an empty object when values are undefined", function(){
39
- expect(I18n.prepareOptions(undefined, undefined)).toEqual({});
40
- });
41
- });