i18n-js 3.2.1 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) 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/config.yml +5 -0
  6. data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
  8. data/.github/dependabot.yml +15 -0
  9. data/.github/workflows/ruby-tests.yml +73 -0
  10. data/.gitignore +13 -7
  11. data/.rubocop.yml +19 -0
  12. data/CHANGELOG.md +45 -386
  13. data/CODE_OF_CONDUCT.md +74 -0
  14. data/CONTRIBUTING.md +79 -0
  15. data/Gemfile +3 -0
  16. data/LICENSE.md +20 -0
  17. data/MIGRATING_FROM_V3_TO_V4.md +191 -0
  18. data/README.md +439 -791
  19. data/Rakefile +10 -20
  20. data/bin/release +81 -0
  21. data/exe/i18n +5 -0
  22. data/i18n-js.gemspec +51 -29
  23. data/lib/guard/i18n-js/templates/Guardfile +10 -0
  24. data/lib/guard/i18n-js/version.rb +13 -0
  25. data/lib/guard/i18n-js.rb +95 -0
  26. data/lib/i18n-js/clean_hash.rb +13 -0
  27. data/lib/i18n-js/cli/check_command.rb +17 -0
  28. data/lib/i18n-js/cli/command.rb +79 -0
  29. data/lib/i18n-js/cli/export_command.rb +95 -0
  30. data/lib/i18n-js/cli/init_command.rb +52 -0
  31. data/lib/i18n-js/cli/lint_scripts_command.rb +157 -0
  32. data/lib/i18n-js/cli/lint_translations_command.rb +155 -0
  33. data/lib/i18n-js/cli/plugins_command.rb +67 -0
  34. data/lib/i18n-js/cli/ui.rb +64 -0
  35. data/lib/i18n-js/cli/version_command.rb +18 -0
  36. data/lib/i18n-js/cli.rb +66 -0
  37. data/lib/i18n-js/embed_fallback_translations_plugin.rb +70 -0
  38. data/lib/i18n-js/export_files_plugin.rb +103 -0
  39. data/lib/i18n-js/lint.js +150645 -0
  40. data/lib/i18n-js/lint.ts +196 -0
  41. data/lib/i18n-js/listen.rb +96 -0
  42. data/lib/i18n-js/plugin.rb +103 -0
  43. data/lib/i18n-js/schema.rb +216 -0
  44. data/lib/i18n-js/sort_hash.rb +12 -0
  45. data/lib/i18n-js/version.rb +5 -0
  46. data/lib/i18n-js.rb +107 -1
  47. data/package.json +5 -20
  48. metadata +153 -181
  49. data/.editorconfig +0 -24
  50. data/.npmignore +0 -27
  51. data/.travis.yml +0 -36
  52. data/Appraisals +0 -32
  53. data/app/assets/javascripts/i18n/filtered.js.erb +0 -23
  54. data/app/assets/javascripts/i18n/shims.js +0 -208
  55. data/app/assets/javascripts/i18n/translations.js +0 -3
  56. data/app/assets/javascripts/i18n.js +0 -1077
  57. data/gemfiles/i18n_0_6.gemfile +0 -7
  58. data/gemfiles/i18n_0_7.gemfile +0 -7
  59. data/gemfiles/i18n_0_8.gemfile +0 -7
  60. data/gemfiles/i18n_0_9.gemfile +0 -7
  61. data/gemfiles/i18n_1_0.gemfile +0 -7
  62. data/gemfiles/i18n_1_1.gemfile +0 -7
  63. data/gemfiles/i18n_1_2.gemfile +0 -7
  64. data/gemfiles/i18n_1_3.gemfile +0 -7
  65. data/gemfiles/i18n_1_4.gemfile +0 -7
  66. data/gemfiles/i18n_1_5.gemfile +0 -7
  67. data/lib/i18n/js/dependencies.rb +0 -59
  68. data/lib/i18n/js/engine.rb +0 -87
  69. data/lib/i18n/js/fallback_locales.rb +0 -70
  70. data/lib/i18n/js/formatters/base.rb +0 -23
  71. data/lib/i18n/js/formatters/js.rb +0 -31
  72. data/lib/i18n/js/formatters/json.rb +0 -13
  73. data/lib/i18n/js/middleware.rb +0 -82
  74. data/lib/i18n/js/private/hash_with_symbol_keys.rb +0 -36
  75. data/lib/i18n/js/segment.rb +0 -75
  76. data/lib/i18n/js/utils.rb +0 -65
  77. data/lib/i18n/js/version.rb +0 -7
  78. data/lib/i18n/js.rb +0 -259
  79. data/lib/rails/generators/i18n/js/config/config_generator.rb +0 -19
  80. data/lib/rails/generators/i18n/js/config/templates/i18n-js.yml +0 -27
  81. data/lib/tasks/export.rake +0 -8
  82. data/spec/fixtures/custom_path.yml +0 -5
  83. data/spec/fixtures/default.yml +0 -5
  84. data/spec/fixtures/erb.yml +0 -5
  85. data/spec/fixtures/except_condition.yml +0 -7
  86. data/spec/fixtures/js_export_dir_custom.yml +0 -7
  87. data/spec/fixtures/js_export_dir_none.yml +0 -6
  88. data/spec/fixtures/js_extend_parent.yml +0 -6
  89. data/spec/fixtures/js_extend_segment.yml +0 -6
  90. data/spec/fixtures/js_file_per_locale.yml +0 -7
  91. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml +0 -4
  92. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml +0 -6
  93. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml +0 -4
  94. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml +0 -4
  95. data/spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml +0 -4
  96. data/spec/fixtures/js_file_per_locale_without_fallbacks.yml +0 -4
  97. data/spec/fixtures/js_file_with_namespace_and_pretty_print.yml +0 -7
  98. data/spec/fixtures/js_sort_translation_keys_false.yml +0 -6
  99. data/spec/fixtures/js_sort_translation_keys_true.yml +0 -6
  100. data/spec/fixtures/json_only.yml +0 -18
  101. data/spec/fixtures/locales.yml +0 -95
  102. data/spec/fixtures/merge_plurals.yml +0 -6
  103. data/spec/fixtures/multiple_conditions.yml +0 -7
  104. data/spec/fixtures/multiple_conditions_per_locale.yml +0 -7
  105. data/spec/fixtures/multiple_files.yml +0 -7
  106. data/spec/fixtures/no_config.yml +0 -2
  107. data/spec/fixtures/no_scope.yml +0 -4
  108. data/spec/fixtures/simple_scope.yml +0 -5
  109. data/spec/js/currency.spec.js +0 -62
  110. data/spec/js/current_locale.spec.js +0 -19
  111. data/spec/js/dates.spec.js +0 -265
  112. data/spec/js/defaults.spec.js +0 -31
  113. data/spec/js/extend.spec.js +0 -110
  114. data/spec/js/interpolation.spec.js +0 -124
  115. data/spec/js/jasmine/MIT.LICENSE +0 -20
  116. data/spec/js/jasmine/jasmine-html.js +0 -190
  117. data/spec/js/jasmine/jasmine.css +0 -166
  118. data/spec/js/jasmine/jasmine.js +0 -2476
  119. data/spec/js/jasmine/jasmine_favicon.png +0 -0
  120. data/spec/js/locales.spec.js +0 -31
  121. data/spec/js/localization.spec.js +0 -48
  122. data/spec/js/numbers.spec.js +0 -170
  123. data/spec/js/placeholder.spec.js +0 -24
  124. data/spec/js/pluralization.spec.js +0 -211
  125. data/spec/js/prepare_options.spec.js +0 -41
  126. data/spec/js/require.js +0 -2083
  127. data/spec/js/specs.html +0 -49
  128. data/spec/js/specs_requirejs.html +0 -72
  129. data/spec/js/translate.spec.js +0 -284
  130. data/spec/js/translations.js +0 -163
  131. data/spec/js/utility_functions.spec.js +0 -20
  132. data/spec/ruby/i18n/js/fallback_locales_spec.rb +0 -84
  133. data/spec/ruby/i18n/js/segment_spec.rb +0 -219
  134. data/spec/ruby/i18n/js/utils_spec.rb +0 -106
  135. data/spec/ruby/i18n/js_spec.rb +0 -663
  136. data/spec/spec_helper.rb +0 -79
  137. 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,48 +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("localizes number", function(){
14
- expect(I18n.l("number", 1234567)).toEqual("1,234,567.000");
15
- });
16
-
17
- it("localizes currency", function(){
18
- expect(I18n.l("currency", 1234567)).toEqual("$1,234,567.00");
19
- });
20
-
21
- it("localizes date strings", function(){
22
- I18n.locale = "pt-BR";
23
-
24
- expect(I18n.l("date.formats.default", "2009-11-29")).toEqual("29/11/2009");
25
- expect(I18n.l("date.formats.short", "2009-01-07")).toEqual("07 de Janeiro");
26
- expect(I18n.l("date.formats.long", "2009-01-07")).toEqual("07 de Janeiro de 2009");
27
- });
28
-
29
- it("localizes time strings", function(){
30
- I18n.locale = "pt-BR";
31
-
32
- expect(I18n.l("time.formats.default", "2009-11-29 15:07:59")).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
33
- expect(I18n.l("time.formats.short", "2009-01-07 09:12:35")).toEqual("07/01, 09:12 h");
34
- expect(I18n.l("time.formats.long", "2009-11-29 15:07:59")).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
35
- });
36
-
37
- it("localizes date/time strings with placeholders", function(){
38
- I18n.locale = "pt-BR";
39
-
40
- expect(I18n.l("date.formats.short_with_placeholders", "2009-01-07", { p1: "!", p2: "?" })).toEqual("07 de Janeiro ! ?");
41
- expect(I18n.l("time.formats.short_with_placeholders", "2009-01-07 09:12:35", { p1: "!" })).toEqual("07/01, 09:12 h !");
42
- });
43
-
44
- it("localizes percentage", function(){
45
- I18n.locale = "pt-BR";
46
- expect(I18n.l("percentage", 123.45)).toEqual("123,45%");
47
- });
48
- });
@@ -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,211 +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 alias", function() {
14
- expect(I18n.p).toEqual(I18n.pluralize);
15
- });
16
-
17
- it("pluralizes scope", function(){
18
- expect(I18n.p(0, "inbox")).toEqual("You have no messages");
19
- expect(I18n.p(1, "inbox")).toEqual("You have 1 message");
20
- expect(I18n.p(5, "inbox")).toEqual("You have 5 messages");
21
- });
22
-
23
- it("pluralizes using the 'other' scope", function(){
24
- I18n.translations["en"]["inbox"]["zero"] = null;
25
- expect(I18n.p(0, "inbox")).toEqual("You have 0 messages");
26
- });
27
-
28
- it("pluralizes using the 'zero' scope", function(){
29
- I18n.translations["en"]["inbox"]["zero"] = "No messages (zero)";
30
-
31
- expect(I18n.p(0, "inbox")).toEqual("No messages (zero)");
32
- });
33
-
34
- it("pluralizes using negative values", function(){
35
- expect(I18n.p(-1, "inbox")).toEqual("You have -1 messages");
36
- expect(I18n.p(-5, "inbox")).toEqual("You have -5 messages");
37
- });
38
-
39
- it("returns missing translation", function(){
40
- expect(I18n.p(-1, "missing")).toEqual('[missing "en.missing" translation]');
41
- });
42
-
43
- it("pluralizes using multiple placeholders", function(){
44
- actual = I18n.p(1, "unread", {unread: 5});
45
- expect(actual).toEqual("You have 1 new message (5 unread)");
46
-
47
- actual = I18n.p(10, "unread", {unread: 2});
48
- expect(actual).toEqual("You have 10 new messages (2 unread)");
49
-
50
- actual = I18n.p(0, "unread", {unread: 5});
51
- expect(actual).toEqual("You have no new messages (5 unread)");
52
- });
53
-
54
- it("allows empty strings", function(){
55
- I18n.translations["en"]["inbox"]["zero"] = "";
56
-
57
- expect(I18n.p(0, "inbox")).toEqual("");
58
- });
59
-
60
- it("returns missing message on null values", function(){
61
- I18n.translations["en"]["sent"]["zero"] = null;
62
- I18n.translations["en"]["sent"]["one"] = null;
63
- I18n.translations["en"]["sent"]["other"] = null;
64
-
65
- expect(I18n.p(0, "sent")).toEqual('[missing "en.sent.zero" translation]');
66
- expect(I18n.p(1, "sent")).toEqual('[missing "en.sent.one" translation]');
67
- expect(I18n.p(5, "sent")).toEqual('[missing "en.sent.other" translation]');
68
- });
69
-
70
- it("pluralizes using custom rules", function() {
71
- I18n.locale = "custom";
72
-
73
- I18n.pluralization["custom"] = function(count) {
74
- if (count === 0) { return ["zero"]; }
75
- if (count >= 1 && count <= 5) { return ["few", "other"]; }
76
- return ["other"];
77
- };
78
-
79
- I18n.translations["custom"] = {
80
- "things": {
81
- "zero": "No things"
82
- , "few": "A few things"
83
- , "other": "%{count} things"
84
- }
85
- }
86
-
87
- expect(I18n.p(0, "things")).toEqual("No things");
88
- expect(I18n.p(4, "things")).toEqual("A few things");
89
- expect(I18n.p(-4, "things")).toEqual("-4 things");
90
- expect(I18n.p(10, "things")).toEqual("10 things");
91
- });
92
-
93
- it("pluralizes default value", function(){
94
- options = {defaultValue: {
95
- zero: "No things here!"
96
- , one: "There is {{count}} thing here!"
97
- , other: "There are {{count}} things here!"
98
- }};
99
-
100
- expect(I18n.p(0, "things", options)).toEqual("No things here!");
101
- expect(I18n.p(1, "things", options)).toEqual("There is 1 thing here!");
102
- expect(I18n.p(5, "things", options)).toEqual("There are 5 things here!");
103
- });
104
-
105
- it("ignores pluralization when scope exists", function(){
106
- options = {defaultValue: {
107
- zero: "No things here!"
108
- , one: "There is {{count}} thing here!"
109
- , other: "There are {{count}} things here!"
110
- }};
111
-
112
- expect(I18n.p(0, "inbox", options)).toEqual("You have no messages");
113
- expect(I18n.p(1, "inbox", options)).toEqual("You have 1 message");
114
- expect(I18n.p(5, "inbox", options)).toEqual("You have 5 messages");
115
- });
116
-
117
- it("fallback to default locale when I18n.fallbacks is enabled", function() {
118
- I18n.locale = "pt-BR";
119
- I18n.fallbacks = true;
120
- I18n.translations["pt-BR"].inbox= {
121
- one: null
122
- , other: null
123
- , zero: null
124
- };
125
- expect(I18n.p(0, "inbox", { count: 0 })).toEqual("You have no messages");
126
- expect(I18n.p(1, "inbox", { count: 1 })).toEqual("You have 1 message");
127
- expect(I18n.p(5, "inbox", { count: 5 })).toEqual("You have 5 messages");
128
- });
129
-
130
- it("fallback to default locale when I18n.fallbacks is enabled", function() {
131
- I18n.locale = "pt-BR";
132
- I18n.fallbacks = true;
133
- I18n.translations["pt-BR"].inbox= {
134
- one: "Você tem uma mensagem"
135
- , other: null
136
- , zero: "Você não tem nenhuma mensagem"
137
- };
138
- expect(I18n.p(0, "inbox", { count: 0 })).toEqual("Você não tem nenhuma mensagem");
139
- expect(I18n.p(1, "inbox", { count: 1 })).toEqual("Você tem uma mensagem");
140
- expect(I18n.p(5, "inbox", { count: 5 })).toEqual('You have 5 messages');
141
- });
142
-
143
- it("fallback to 'other' scope", function() {
144
- I18n.locale = "pt-BR";
145
- I18n.fallbacks = true;
146
- I18n.translations["pt-BR"].inbox= {
147
- one: "Você tem uma mensagem"
148
- , other: "Você tem {{count}} mensagens"
149
- , zero: null
150
- }
151
- expect(I18n.p(0, "inbox", { count: 0 })).toEqual("Você tem 0 mensagens");
152
- expect(I18n.p(1, "inbox", { count: 1 })).toEqual("Você tem uma mensagem");
153
- expect(I18n.p(5, "inbox", { count: 5 })).toEqual("Você tem 5 mensagens");
154
- });
155
-
156
- it("fallback to defaulValue when defaultValue is string", function() {
157
- I18n.locale = "pt-BR";
158
- I18n.fallbacks = true;
159
- I18n.translations["en"]["inbox"]["zero"] = null;
160
- I18n.translations["en"]["inbox"]["one"] = null;
161
- I18n.translations["en"]["inbox"]["other"] = null;
162
- I18n.translations["pt-BR"].inbox= {
163
- one: "Você tem uma mensagem"
164
- , other: null
165
- , zero: null
166
- }
167
- options = {
168
- defaultValue: "default message"
169
- };
170
- expect(I18n.p(0, "inbox", options)).toEqual("default message");
171
- expect(I18n.p(1, "inbox", options)).toEqual("Você tem uma mensagem");
172
- expect(I18n.p(5, "inbox", options)).toEqual("default message");
173
- });
174
-
175
- it("fallback to defaulValue when defaultValue is an object", function() {
176
- I18n.locale = "pt-BR";
177
- I18n.fallbacks = true;
178
- I18n.translations["en"]["inbox"]["zero"] = null;
179
- I18n.translations["en"]["inbox"]["one"] = null;
180
- I18n.translations["en"]["inbox"]["other"] = null;
181
- I18n.translations["pt-BR"].inbox= {
182
- one: "Você tem uma mensagem"
183
- , other: null
184
- , zero: null
185
- }
186
- options = {
187
- defaultValue: {
188
- zero: "default message for no message"
189
- , one: "default message for 1 message"
190
- , other: "default message for {{count}} messages"
191
- }
192
- };
193
- expect(I18n.p(0, "inbox", options)).toEqual("default message for no message");
194
- expect(I18n.p(1, "inbox", options)).toEqual("Você tem uma mensagem");
195
- expect(I18n.p(5, "inbox", options)).toEqual("default message for 5 messages");
196
- });
197
-
198
- it("fallback to default locale when I18n.fallbacks is enabled and no translations in sub scope", function() {
199
- I18n.locale = "pt-BR";
200
- I18n.fallbacks = true;
201
- I18n.translations["en"]["mailbox"] = {
202
- inbox: I18n.translations["en"].inbox
203
- }
204
-
205
- expect(I18n.translations["pt-BR"]["mailbox"]).toEqual(undefined);
206
- expect(I18n.p(0, "mailbox.inbox", { count: 0 })).toEqual("You have no messages");
207
- expect(I18n.p(1, "mailbox.inbox", { count: 1 })).toEqual("You have 1 message");
208
- expect(I18n.p(5, "mailbox.inbox", { count: 5 })).toEqual("You have 5 messages");
209
- });
210
-
211
- });
@@ -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
- });