i18n-js 3.9.2 → 4.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) 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/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 -561
  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 +425 -951
  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 +152 -198
  49. data/.editorconfig +0 -24
  50. data/.github/workflows/tests.yaml +0 -106
  51. data/.npmignore +0 -27
  52. data/Appraisals +0 -52
  53. data/app/assets/javascripts/i18n/filtered.js.erb +0 -23
  54. data/app/assets/javascripts/i18n/shims.js +0 -240
  55. data/app/assets/javascripts/i18n/translations.js +0 -3
  56. data/app/assets/javascripts/i18n.js +0 -1095
  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_10.gemfile +0 -7
  64. data/gemfiles/i18n_1_2.gemfile +0 -7
  65. data/gemfiles/i18n_1_3.gemfile +0 -7
  66. data/gemfiles/i18n_1_4.gemfile +0 -7
  67. data/gemfiles/i18n_1_5.gemfile +0 -7
  68. data/gemfiles/i18n_1_6.gemfile +0 -7
  69. data/gemfiles/i18n_1_7.gemfile +0 -7
  70. data/gemfiles/i18n_1_8.gemfile +0 -7
  71. data/gemfiles/i18n_1_9.gemfile +0 -7
  72. data/i18njs.png +0 -0
  73. data/lib/i18n/js/dependencies.rb +0 -67
  74. data/lib/i18n/js/engine.rb +0 -87
  75. data/lib/i18n/js/fallback_locales.rb +0 -70
  76. data/lib/i18n/js/formatters/base.rb +0 -25
  77. data/lib/i18n/js/formatters/js.rb +0 -39
  78. data/lib/i18n/js/formatters/json.rb +0 -13
  79. data/lib/i18n/js/middleware.rb +0 -82
  80. data/lib/i18n/js/private/config_store.rb +0 -31
  81. data/lib/i18n/js/private/hash_with_symbol_keys.rb +0 -36
  82. data/lib/i18n/js/segment.rb +0 -81
  83. data/lib/i18n/js/utils.rb +0 -91
  84. data/lib/i18n/js/version.rb +0 -7
  85. data/lib/i18n/js.rb +0 -274
  86. data/lib/rails/generators/i18n/js/config/config_generator.rb +0 -19
  87. data/lib/rails/generators/i18n/js/config/templates/i18n-js.yml +0 -27
  88. data/lib/tasks/export.rake +0 -8
  89. data/spec/fixtures/custom_path.yml +0 -5
  90. data/spec/fixtures/default.yml +0 -5
  91. data/spec/fixtures/erb.yml +0 -5
  92. data/spec/fixtures/except_condition.yml +0 -7
  93. data/spec/fixtures/js_available_locales_custom.yml +0 -1
  94. data/spec/fixtures/js_export_dir_custom.yml +0 -7
  95. data/spec/fixtures/js_export_dir_none.yml +0 -6
  96. data/spec/fixtures/js_extend_parent.yml +0 -6
  97. data/spec/fixtures/js_extend_segment.yml +0 -6
  98. data/spec/fixtures/js_file_per_locale.yml +0 -7
  99. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml +0 -4
  100. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml +0 -6
  101. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml +0 -4
  102. data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml +0 -4
  103. data/spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml +0 -4
  104. data/spec/fixtures/js_file_per_locale_without_fallbacks.yml +0 -4
  105. data/spec/fixtures/js_file_with_namespace_prefix_and_pretty_print.yml +0 -9
  106. data/spec/fixtures/js_sort_translation_keys_false.yml +0 -6
  107. data/spec/fixtures/js_sort_translation_keys_true.yml +0 -6
  108. data/spec/fixtures/json_only.yml +0 -18
  109. data/spec/fixtures/locales.yml +0 -133
  110. data/spec/fixtures/merge_plurals.yml +0 -6
  111. data/spec/fixtures/merge_plurals_with_no_overrides.yml +0 -4
  112. data/spec/fixtures/merge_plurals_with_partial_overrides.yml +0 -4
  113. data/spec/fixtures/millions.yml +0 -4
  114. data/spec/fixtures/multiple_conditions.yml +0 -7
  115. data/spec/fixtures/multiple_conditions_per_locale.yml +0 -7
  116. data/spec/fixtures/multiple_files.yml +0 -7
  117. data/spec/fixtures/no_config.yml +0 -2
  118. data/spec/fixtures/no_scope.yml +0 -4
  119. data/spec/fixtures/simple_scope.yml +0 -5
  120. data/spec/js/currency.spec.js +0 -62
  121. data/spec/js/current_locale.spec.js +0 -19
  122. data/spec/js/dates.spec.js +0 -276
  123. data/spec/js/defaults.spec.js +0 -31
  124. data/spec/js/extend.spec.js +0 -110
  125. data/spec/js/interpolation.spec.js +0 -124
  126. data/spec/js/jasmine/MIT.LICENSE +0 -20
  127. data/spec/js/jasmine/jasmine-html.js +0 -190
  128. data/spec/js/jasmine/jasmine.css +0 -166
  129. data/spec/js/jasmine/jasmine.js +0 -2476
  130. data/spec/js/jasmine/jasmine_favicon.png +0 -0
  131. data/spec/js/json_parsable.spec.js +0 -14
  132. data/spec/js/locales.spec.js +0 -31
  133. data/spec/js/localization.spec.js +0 -78
  134. data/spec/js/numbers.spec.js +0 -174
  135. data/spec/js/placeholder.spec.js +0 -24
  136. data/spec/js/pluralization.spec.js +0 -228
  137. data/spec/js/prepare_options.spec.js +0 -41
  138. data/spec/js/require.js +0 -2083
  139. data/spec/js/specs.html +0 -49
  140. data/spec/js/specs_requirejs.html +0 -72
  141. data/spec/js/translate.spec.js +0 -304
  142. data/spec/js/translations.js +0 -188
  143. data/spec/js/utility_functions.spec.js +0 -20
  144. data/spec/ruby/i18n/js/fallback_locales_spec.rb +0 -84
  145. data/spec/ruby/i18n/js/segment_spec.rb +0 -286
  146. data/spec/ruby/i18n/js/utils_spec.rb +0 -138
  147. data/spec/ruby/i18n/js_spec.rb +0 -797
  148. data/spec/spec_helper.rb +0 -80
  149. data/yarn.lock +0 -138
data/spec/js/specs.html DELETED
@@ -1,49 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Jasmine Spec Runner</title>
6
- <link rel="stylesheet" href="jasmine/jasmine.css" type="text/css">
7
- </head>
8
-
9
- <body>
10
- <!-- load jasmine -->
11
- <script type="text/javascript" src="jasmine/jasmine.js"></script>
12
- <script type="text/javascript" src="jasmine/jasmine-html.js"></script>
13
-
14
- <!-- load your javascript files -->
15
- <script type="text/javascript" src="../../app/assets/javascripts/i18n.js"></script>
16
- <script type="text/javascript">
17
- function require(path) {
18
- if (path.match(/i18n/)) {
19
- return I18n;
20
- } else {
21
- return Translations;
22
- }
23
- }
24
- </script>
25
-
26
- <!-- load your spec files -->
27
- <script type="text/javascript" src="translations.js"></script>
28
- <script type="text/javascript" src="currency.spec.js"></script>
29
- <script type="text/javascript" src="current_locale.spec.js"></script>
30
- <script type="text/javascript" src="dates.spec.js"></script>
31
- <script type="text/javascript" src="defaults.spec.js"></script>
32
- <script type="text/javascript" src="interpolation.spec.js"></script>
33
- <script type="text/javascript" src="localization.spec.js"></script>
34
- <script type="text/javascript" src="locales.spec.js"></script>
35
- <script type="text/javascript" src="numbers.spec.js"></script>
36
- <script type="text/javascript" src="placeholder.spec.js"></script>
37
- <script type="text/javascript" src="pluralization.spec.js"></script>
38
- <script type="text/javascript" src="prepare_options.spec.js"></script>
39
- <script type="text/javascript" src="translate.spec.js"></script>
40
- <script type="text/javascript" src="utility_functions.spec.js"></script>
41
- <script type="text/javascript" src="extend.spec.js"></script>
42
-
43
- <!-- run specs -->
44
- <script type="text/javascript">
45
- jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
46
- jasmine.getEnv().execute();
47
- </script>
48
- </body>
49
- </html>
@@ -1,72 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Jasmine Spec Runner</title>
6
- <link rel="stylesheet" href="jasmine/jasmine.css" type="text/css">
7
- </head>
8
-
9
- <body>
10
- <!-- load jasmine -->
11
- <script type="text/javascript" src="jasmine/jasmine.js"></script>
12
- <script type="text/javascript" src="jasmine/jasmine-html.js"></script>
13
-
14
- <!-- load your javascript files -->
15
- <script type="text/javascript" src="require.js"></script>
16
-
17
- <script type="text/javascript">
18
- // Prepare requirejs shims to wrap each test so that it will work with the
19
- // require syntax loading
20
- var testScripts = [
21
- "./translate.spec.js",
22
- "./currency.spec.js",
23
- "./current_locale.spec.js",
24
- "./dates.spec.js",
25
- "./defaults.spec.js",
26
- "./interpolation.spec.js",
27
- "./localization.spec.js",
28
- "./numbers.spec.js",
29
- "./placeholder.spec.js",
30
- "./pluralization.spec.js",
31
- "./prepare_options.spec.js",
32
- "./translate.spec.js",
33
- "./utility_functions.spec.js",
34
- "./extend.spec.js"
35
- ];
36
- var shims = {};
37
- for(var i = 0; i < testScripts.length; i++) {
38
- shims[ testScripts[i] ] = {
39
- "deps": ["i18n"]
40
- };
41
- }
42
- require.config(
43
- {
44
- "baseUrl" : "./",
45
- "paths": {
46
- "i18n": "../../app/assets/javascripts/i18n"
47
- },
48
- /* Since the i18n.js file explicitly names its module 'i18n', but each
49
- spec uses the full path in the require statement, it appears that
50
- loading fails. This map will map the full path to the short form.
51
- */
52
- "map": {
53
- "*": {
54
- "../../app/assets/javascripts/i18n": "i18n"
55
- }
56
- },
57
- "shim": shims
58
- });
59
- require((["i18n", './translations']).concat(testScripts),
60
- function(I18n, translationFactory) {
61
- // Example for using the translation factory
62
- I18n.translations = translationFactory();
63
- console.log(I18n.t('hello'));
64
-
65
- // Execute the specs
66
- jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
67
- jasmine.getEnv().execute();
68
- });
69
- </script>
70
-
71
- </body>
72
- </html>
@@ -1,304 +0,0 @@
1
- var I18n = require("../../app/assets/javascripts/i18n")
2
- , Translations = require("./translations")
3
- ;
4
-
5
- describe("Translate", 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.t).toEqual(jasmine.any(Function));
15
- expect(I18n.t).not.toBe(I18n.translate);
16
- });
17
-
18
- it("returns translation for single scope", function(){
19
- expect(I18n.translate("hello")).toEqual("Hello World!");
20
- });
21
-
22
- it("returns translation with 't' shortcut", function(){
23
- var t = I18n.t;
24
- expect(t("hello")).toEqual("Hello World!");
25
- });
26
-
27
- it("returns translation as object", function(){
28
- expect(I18n.translate("greetings")).toEqual(I18n.translations.en.greetings);
29
- });
30
-
31
- it("returns missing message translation for valid scope with null", function(){
32
- actual = I18n.translate("null_key");
33
- expected = '[missing "en.null_key" translation]';
34
- expect(actual).toEqual(expected);
35
- });
36
-
37
- it("returns missing message translation for invalid scope", function(){
38
- actual = I18n.translate("invalid.scope");
39
- expected = '[missing "en.invalid.scope" translation]';
40
- expect(actual).toEqual(expected);
41
- });
42
-
43
- it("returns missing message translation with provided locale for invalid scope", function(){
44
- actual = I18n.translate("invalid.scope", { locale: "ja" });
45
- expected = '[missing "ja.invalid.scope" translation]';
46
- expect(actual).toEqual(expected);
47
- });
48
-
49
- it("returns guessed translation if missingBehaviour is set to guess", function(){
50
- I18n.missingBehaviour = 'guess'
51
-
52
- var actual_1 = I18n.translate("invalid.thisIsAutomaticallyGeneratedTranslation");
53
- var expected_1 = 'this is automatically generated translation';
54
- expect(actual_1).toEqual(expected_1);
55
-
56
- var actual_2 = I18n.translate("invalid.this_is_automatically_generated_translation");
57
- var expected_2 = 'this is automatically generated translation';
58
- expect(actual_2).toEqual(expected_2);
59
- });
60
-
61
- it("returns guessed translation with prefix if missingBehaviour is set to guess and prefix is also provided", function(){
62
- I18n.missingBehaviour = 'guess'
63
- I18n.missingTranslationPrefix = 'EE: '
64
- actual = I18n.translate("invalid.thisIsAutomaticallyGeneratedTranslation");
65
- expected = 'EE: this is automatically generated translation';
66
- expect(actual).toEqual(expected);
67
- });
68
-
69
- it("returns missing message translation for valid scope with scope", function(){
70
- actual = I18n.translate("monster", {scope: "greetings"});
71
- expected = '[missing "en.greetings.monster" translation]';
72
- expect(actual).toEqual(expected);
73
- });
74
-
75
- it("returns translation for single scope on a custom locale", function(){
76
- I18n.locale = "pt-BR";
77
- expect(I18n.translate("hello")).toEqual("Olá Mundo!");
78
- });
79
-
80
- it("returns translation for multiple scopes", function(){
81
- expect(I18n.translate("greetings.stranger")).toEqual("Hello stranger!");
82
- });
83
-
84
- it("returns translation with default locale option", function(){
85
- expect(I18n.translate("hello", {locale: "en"})).toEqual("Hello World!");
86
- expect(I18n.translate("hello", {locale: "pt-BR"})).toEqual("Olá Mundo!");
87
- });
88
-
89
- it("fallbacks to the default locale when I18n.fallbacks is enabled", function(){
90
- I18n.locale = "pt-BR";
91
- I18n.fallbacks = true;
92
- expect(I18n.translate("greetings.stranger")).toEqual("Hello stranger!");
93
- });
94
-
95
- it("fallbacks to default locale when providing an unknown locale", function(){
96
- I18n.locale = "fr";
97
- I18n.fallbacks = true;
98
- expect(I18n.translate("greetings.stranger")).toEqual("Hello stranger!");
99
- });
100
-
101
- it("fallbacks to less specific locale", function(){
102
- I18n.locale = "de-DE";
103
- I18n.fallbacks = true;
104
- expect(I18n.translate("hello")).toEqual("Hallo Welt!");
105
- });
106
-
107
- describe("when a 3-part locale is used", function(){
108
- beforeEach(function(){
109
- I18n.locale = "zh-Hant-TW";
110
- I18n.fallbacks = true;
111
- });
112
-
113
- it("fallbacks to 2-part locale when absent", function(){
114
- expect(I18n.translate("cat")).toEqual("貓");
115
- });
116
-
117
- it("fallbacks to 1-part locale when 2-part missing requested translation", function(){
118
- expect(I18n.translate("dog")).toEqual("狗");
119
- });
120
-
121
- it("fallbacks to 2-part for the first time", function(){
122
- expect(I18n.translate("dragon")).toEqual("龍");
123
- });
124
- });
125
-
126
- it("fallbacks using custom rules (function)", function(){
127
- I18n.locale = "no";
128
- I18n.fallbacks = true;
129
- I18n.locales["no"] = function() {
130
- return ["nb"];
131
- };
132
-
133
- expect(I18n.translate("hello")).toEqual("Hei Verden!");
134
- });
135
-
136
- it("fallbacks using custom rules (array)", function() {
137
- I18n.locale = "no";
138
- I18n.fallbacks = true;
139
- I18n.locales["no"] = ["no", "nb"];
140
-
141
- expect(I18n.translate("hello")).toEqual("Hei Verden!");
142
- });
143
-
144
- it("fallbacks using custom rules (string)", function() {
145
- I18n.locale = "no";
146
- I18n.fallbacks = true;
147
- I18n.locales["no"] = "nb";
148
-
149
- expect(I18n.translate("hello")).toEqual("Hei Verden!");
150
- });
151
-
152
- describe("when provided default values", function() {
153
- it("uses scope provided in defaults if scope doesn't exist", function() {
154
- actual = I18n.translate("Hello!", {defaults: [{scope: "greetings.stranger"}]});
155
- expect(actual).toEqual("Hello stranger!");
156
- });
157
-
158
- it("continues to fallback until a scope is found", function() {
159
- var defaults = [{scope: "foo"}, {scope: "hello"}];
160
-
161
- actual = I18n.translate("foo", {defaults: defaults});
162
- expect(actual).toEqual("Hello World!");
163
- });
164
-
165
- it("uses message if specified as a default", function() {
166
- var defaults = [{message: "Hello all!"}];
167
- actual = I18n.translate("foo", {defaults: defaults});
168
- expect(actual).toEqual("Hello all!");
169
- });
170
-
171
- it("uses the first message if no scopes are found", function() {
172
- var defaults = [
173
- {scope: "bar"}
174
- , {message: "Hello all!"}
175
- , {scope: "hello"}];
176
- actual = I18n.translate("foo", {defaults: defaults});
177
- expect(actual).toEqual("Hello all!");
178
- });
179
-
180
- it("uses default value if no scope is found", function() {
181
- var options = {
182
- defaults: [{scope: "bar"}]
183
- , defaultValue: "Hello all!"
184
- };
185
- actual = I18n.translate("foo", options);
186
- expect(actual).toEqual("Hello all!");
187
- });
188
-
189
- it("uses default scope over default value if default scope is found", function() {
190
- var options = {
191
- defaults: [{scope: "hello"}]
192
- , defaultValue: "Hello all!"
193
- };
194
- actual = I18n.translate("foo", options);
195
- expect(actual).toEqual("Hello World!");
196
- })
197
-
198
- it("uses default value with lazy evaluation", function () {
199
- var options = {
200
- defaults: [{scope: "bar"}]
201
- , defaultValue: function(scope) {
202
- return scope.toUpperCase();
203
- }
204
- };
205
- actual = I18n.translate("foo", options);
206
- expect(actual).toEqual("FOO");
207
- })
208
-
209
- it("pluralizes using the correct scope if translation is found within default scope", function() {
210
- expect(I18n.translations["en"]["mailbox"]).toEqual(undefined);
211
- actual = I18n.translate("mailbox.inbox", {count: 1, defaults: [{scope: "inbox"}]});
212
- expected = I18n.translate("inbox", {count: 1})
213
- expect(actual).toEqual(expected)
214
- })
215
- });
216
-
217
- it("uses default value for simple translation", function(){
218
- actual = I18n.translate("warning", {defaultValue: "Warning!"});
219
- expect(actual).toEqual("Warning!");
220
- });
221
-
222
- it("uses default value for plural translation", function(){
223
- actual = I18n.translate("message", {defaultValue: { one: '%{count} message', other: '%{count} messages'}, count: 1});
224
- expect(actual).toEqual("1 message");
225
- });
226
-
227
- it("uses default value for unknown locale", function(){
228
- I18n.locale = "fr";
229
- actual = I18n.translate("warning", {defaultValue: "Warning!"});
230
- expect(actual).toEqual("Warning!");
231
- });
232
-
233
- it("uses default value with interpolation", function(){
234
- actual = I18n.translate(
235
- "alert",
236
- {defaultValue: "Attention! {{message}}", message: "You're out of quota!"}
237
- );
238
-
239
- expect(actual).toEqual("Attention! You're out of quota!");
240
- });
241
-
242
- it("ignores default value when scope exists", function(){
243
- actual = I18n.translate("hello", {defaultValue: "What's up?"});
244
- expect(actual).toEqual("Hello World!");
245
- });
246
-
247
- it("returns translation for custom scope separator", function(){
248
- I18n.defaultSeparator = "•";
249
- actual = I18n.translate("greetings•stranger");
250
- expect(actual).toEqual("Hello stranger!");
251
- });
252
-
253
- it("returns boolean values", function() {
254
- expect(I18n.translate("booleans.yes")).toEqual(true);
255
- expect(I18n.translate("booleans.no")).toEqual(false);
256
- });
257
-
258
- it("escapes $ when doing substitution (IE)", function(){
259
- I18n.locale = "en";
260
-
261
- expect(I18n.translate("paid", {price: "$0"})).toEqual("You were paid $0");
262
- expect(I18n.translate("paid", {price: "$0.12"})).toEqual("You were paid $0.12");
263
- expect(I18n.translate("paid", {price: "$1.35"})).toEqual("You were paid $1.35");
264
- });
265
-
266
- it("replaces all occurrences of escaped $", function(){
267
- I18n.locale = "en";
268
-
269
- expect(I18n.translate("paid_with_vat", {
270
- price: "$0.12",
271
- vat: "$0.02"}
272
- )).toEqual("You were paid $0.12 (incl. VAT $0.02)");
273
- });
274
-
275
- it("sets default scope", function(){
276
- var options = {scope: "greetings"};
277
- expect(I18n.translate("stranger", options)).toEqual("Hello stranger!");
278
- });
279
-
280
- it("accepts the scope as an array", function(){
281
- expect(I18n.translate(["greetings", "stranger"])).toEqual("Hello stranger!");
282
- });
283
-
284
- it("accepts the scope as an array using a base scope", function(){
285
- expect(I18n.translate(["stranger"], {scope: "greetings"})).toEqual("Hello stranger!");
286
- });
287
-
288
- it("returns an array with values interpolated", function(){
289
- var options = {value: 314};
290
- expect(I18n.translate("arrayWithParams", options)).toEqual([
291
- null,
292
- "An item with a param of " + options.value,
293
- "Another item with a param of " + options.value,
294
- "A last item with a param of " + options.value,
295
- ["An", "array", "of", "strings"],
296
- {foo: "bar"}
297
- ]);
298
- });
299
-
300
-
301
- it("returns value with key containing dot but different separator specified", function() {
302
- expect(I18n.t(["A implies B means something."], {scope: "sentences_with_dots", separator: "|"})).toEqual("A implies B means that when A is true, B must be true.");
303
- });
304
- });
@@ -1,188 +0,0 @@
1
-
2
- ;(function(){
3
- var generator = function() {
4
- var Translations = {};
5
-
6
- Translations.en = {
7
- hello: "Hello World!"
8
- , paid: "You were paid %{price}"
9
-
10
- , paid_with_vat: "You were paid %{price} (incl. VAT %{vat})"
11
-
12
- , booleans: {
13
- yes: true,
14
- no: false
15
- }
16
-
17
- , greetings: {
18
- stranger: "Hello stranger!"
19
- , name: "Hello {{name}}!"
20
- }
21
-
22
- , profile: {
23
- details: "{{name}} is {{age}}-years old"
24
- }
25
-
26
- , inbox: {
27
- one: "You have {{count}} message"
28
- , other: "You have {{count}} messages"
29
- , zero: "You have no messages"
30
- }
31
-
32
- , sent: {
33
- one: null
34
- , other: null
35
- , zero: null
36
- }
37
-
38
- , unread: {
39
- one: "You have 1 new message ({{unread}} unread)"
40
- , other: "You have {{count}} new messages ({{unread}} unread)"
41
- , zero: "You have no new messages ({{unread}} unread)"
42
- }
43
-
44
- , number: {
45
- human: {
46
- storage_units: {
47
- units: {
48
- "byte": {
49
- one: "Byte"
50
- , other: "Bytes"
51
- }
52
- , "kb": "KB"
53
- , "mb": "MB"
54
- , "gb": "GB"
55
- , "tb": "TB"
56
- }
57
- }
58
- }
59
- }
60
-
61
- , extended: {
62
- number: {
63
- human: {
64
- storage_units: {
65
- units: {
66
- "mb": "Megabyte"
67
- }
68
- }
69
- }
70
- }
71
- }
72
-
73
- , arrayWithParams: [
74
- null,
75
- "An item with a param of {{value}}",
76
- "Another item with a param of {{value}}",
77
- "A last item with a param of {{value}}",
78
- ["An", "array", "of", "strings"],
79
- {foo: "bar"}
80
- ]
81
-
82
- , null_key: null,
83
-
84
- sentences_with_dots: {
85
- "A implies B means something.": "A implies B means that when A is true, B must be true."
86
- }
87
- };
88
-
89
- Translations["en-US"] = {
90
- date: {
91
- formats: {
92
- "default": "%d/%m/%Y"
93
- , "short": "%d de %B"
94
- , "long": "%d de %B de %Y"
95
- }
96
-
97
- , day_names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
98
- , abbr_day_names: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
99
- , month_names: [null, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
100
- , abbr_month_names: [null, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"]
101
- , meridian: ["am", "pm"]
102
- }
103
- };
104
-
105
- Translations["pt-BR"] = {
106
- hello: "Olá Mundo!"
107
-
108
- , number: {
109
- currency: {
110
- format: {
111
- delimiter: ".",
112
- format: "%u %n",
113
- precision: 2,
114
- separator: ",",
115
- unit: "R$"
116
- }
117
- }
118
- , percentage: {
119
- format: {
120
- delimiter: ""
121
- , separator: ","
122
- , precision: 2
123
- }
124
- }
125
- }
126
-
127
- , date: {
128
- formats: {
129
- "default": "%d/%m/%Y"
130
- , "short": "%d de %B"
131
- , "long": "%d de %B de %Y"
132
- , "short_with_placeholders": "%d de %B {{p1}} {{p2}}"
133
- }
134
- , day_names: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"]
135
- , abbr_day_names: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"]
136
- , month_names: [null, "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]
137
- , abbr_month_names: [null, "Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]
138
- }
139
-
140
- , time: {
141
- formats: {
142
- "default": "%A, %d de %B de %Y, %H:%M h"
143
- , "short": "%d/%m, %H:%M h"
144
- , "long": "%A, %d de %B de %Y, %H:%M h"
145
- , "short_with_placeholders": "%d/%m, %H:%M h {{p1}}"
146
- }
147
- , am: "AM"
148
- , pm: "PM"
149
- }
150
- };
151
-
152
- Translations["de"] = {
153
- hello: "Hallo Welt!"
154
- , date: {
155
- day_names: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]
156
- }
157
-
158
- , time: {
159
- am: "de:AM"
160
- , pm: "de:PM"
161
- }
162
- };
163
-
164
- Translations["nb"] = {
165
- hello: "Hei Verden!"
166
- };
167
-
168
- Translations["zh-Hant"] = {
169
- cat: "貓"
170
- , dragon: "龍"
171
- };
172
-
173
- Translations["zh"] = {
174
- dog: "狗"
175
- , dragon: "龙"
176
- };
177
-
178
- return Translations;
179
- };
180
-
181
- if (typeof define === 'function' && define.amd) {
182
- define(function() { return generator; });
183
- } else if (typeof(exports) === "undefined") {
184
- window.Translations = generator;
185
- } else {
186
- module.exports = generator;
187
- }
188
- })();
@@ -1,20 +0,0 @@
1
- var I18n = require("../../app/assets/javascripts/i18n");
2
-
3
- describe("Utility Functions", function(){
4
- beforeEach(function(){
5
- I18n.reset();
6
- });
7
-
8
- describe("I18n.lookup", function() {
9
- it("does not change locale on failed lookup", function(){
10
- var fallback_locales = ['fallback1', 'fallback2'];
11
-
12
- I18n.locales['lang'] = fallback_locales.slice();
13
- expect(I18n.locales.lang).toEqual(fallback_locales);
14
-
15
- I18n.lookup('anything', {locale: 'lang'})
16
- expect(I18n.locales.lang).toEqual(fallback_locales);
17
- });
18
-
19
- })
20
- });