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.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +4 -0
- data/.github/FUNDING.yml +3 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
- data/.github/ISSUE_TEMPLATE/config.yml +5 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ruby-tests.yml +73 -0
- data/.gitignore +13 -7
- data/.rubocop.yml +19 -0
- data/CHANGELOG.md +45 -386
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/MIGRATING_FROM_V3_TO_V4.md +191 -0
- data/README.md +439 -791
- data/Rakefile +10 -20
- data/bin/release +81 -0
- data/exe/i18n +5 -0
- data/i18n-js.gemspec +51 -29
- data/lib/guard/i18n-js/templates/Guardfile +10 -0
- data/lib/guard/i18n-js/version.rb +13 -0
- data/lib/guard/i18n-js.rb +95 -0
- data/lib/i18n-js/clean_hash.rb +13 -0
- data/lib/i18n-js/cli/check_command.rb +17 -0
- data/lib/i18n-js/cli/command.rb +79 -0
- data/lib/i18n-js/cli/export_command.rb +95 -0
- data/lib/i18n-js/cli/init_command.rb +52 -0
- data/lib/i18n-js/cli/lint_scripts_command.rb +157 -0
- data/lib/i18n-js/cli/lint_translations_command.rb +155 -0
- data/lib/i18n-js/cli/plugins_command.rb +67 -0
- data/lib/i18n-js/cli/ui.rb +64 -0
- data/lib/i18n-js/cli/version_command.rb +18 -0
- data/lib/i18n-js/cli.rb +66 -0
- data/lib/i18n-js/embed_fallback_translations_plugin.rb +70 -0
- data/lib/i18n-js/export_files_plugin.rb +103 -0
- data/lib/i18n-js/lint.js +150645 -0
- data/lib/i18n-js/lint.ts +196 -0
- data/lib/i18n-js/listen.rb +96 -0
- data/lib/i18n-js/plugin.rb +103 -0
- data/lib/i18n-js/schema.rb +216 -0
- data/lib/i18n-js/sort_hash.rb +12 -0
- data/lib/i18n-js/version.rb +5 -0
- data/lib/i18n-js.rb +107 -1
- data/package.json +5 -20
- metadata +153 -181
- data/.editorconfig +0 -24
- data/.npmignore +0 -27
- data/.travis.yml +0 -36
- data/Appraisals +0 -32
- data/app/assets/javascripts/i18n/filtered.js.erb +0 -23
- data/app/assets/javascripts/i18n/shims.js +0 -208
- data/app/assets/javascripts/i18n/translations.js +0 -3
- data/app/assets/javascripts/i18n.js +0 -1077
- data/gemfiles/i18n_0_6.gemfile +0 -7
- data/gemfiles/i18n_0_7.gemfile +0 -7
- data/gemfiles/i18n_0_8.gemfile +0 -7
- data/gemfiles/i18n_0_9.gemfile +0 -7
- data/gemfiles/i18n_1_0.gemfile +0 -7
- data/gemfiles/i18n_1_1.gemfile +0 -7
- data/gemfiles/i18n_1_2.gemfile +0 -7
- data/gemfiles/i18n_1_3.gemfile +0 -7
- data/gemfiles/i18n_1_4.gemfile +0 -7
- data/gemfiles/i18n_1_5.gemfile +0 -7
- data/lib/i18n/js/dependencies.rb +0 -59
- data/lib/i18n/js/engine.rb +0 -87
- data/lib/i18n/js/fallback_locales.rb +0 -70
- data/lib/i18n/js/formatters/base.rb +0 -23
- data/lib/i18n/js/formatters/js.rb +0 -31
- data/lib/i18n/js/formatters/json.rb +0 -13
- data/lib/i18n/js/middleware.rb +0 -82
- data/lib/i18n/js/private/hash_with_symbol_keys.rb +0 -36
- data/lib/i18n/js/segment.rb +0 -75
- data/lib/i18n/js/utils.rb +0 -65
- data/lib/i18n/js/version.rb +0 -7
- data/lib/i18n/js.rb +0 -259
- data/lib/rails/generators/i18n/js/config/config_generator.rb +0 -19
- data/lib/rails/generators/i18n/js/config/templates/i18n-js.yml +0 -27
- data/lib/tasks/export.rake +0 -8
- data/spec/fixtures/custom_path.yml +0 -5
- data/spec/fixtures/default.yml +0 -5
- data/spec/fixtures/erb.yml +0 -5
- data/spec/fixtures/except_condition.yml +0 -7
- data/spec/fixtures/js_export_dir_custom.yml +0 -7
- data/spec/fixtures/js_export_dir_none.yml +0 -6
- data/spec/fixtures/js_extend_parent.yml +0 -6
- data/spec/fixtures/js_extend_segment.yml +0 -6
- data/spec/fixtures/js_file_per_locale.yml +0 -7
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml +0 -6
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml +0 -4
- data/spec/fixtures/js_file_per_locale_without_fallbacks.yml +0 -4
- data/spec/fixtures/js_file_with_namespace_and_pretty_print.yml +0 -7
- data/spec/fixtures/js_sort_translation_keys_false.yml +0 -6
- data/spec/fixtures/js_sort_translation_keys_true.yml +0 -6
- data/spec/fixtures/json_only.yml +0 -18
- data/spec/fixtures/locales.yml +0 -95
- data/spec/fixtures/merge_plurals.yml +0 -6
- data/spec/fixtures/multiple_conditions.yml +0 -7
- data/spec/fixtures/multiple_conditions_per_locale.yml +0 -7
- data/spec/fixtures/multiple_files.yml +0 -7
- data/spec/fixtures/no_config.yml +0 -2
- data/spec/fixtures/no_scope.yml +0 -4
- data/spec/fixtures/simple_scope.yml +0 -5
- data/spec/js/currency.spec.js +0 -62
- data/spec/js/current_locale.spec.js +0 -19
- data/spec/js/dates.spec.js +0 -265
- data/spec/js/defaults.spec.js +0 -31
- data/spec/js/extend.spec.js +0 -110
- data/spec/js/interpolation.spec.js +0 -124
- data/spec/js/jasmine/MIT.LICENSE +0 -20
- data/spec/js/jasmine/jasmine-html.js +0 -190
- data/spec/js/jasmine/jasmine.css +0 -166
- data/spec/js/jasmine/jasmine.js +0 -2476
- data/spec/js/jasmine/jasmine_favicon.png +0 -0
- data/spec/js/locales.spec.js +0 -31
- data/spec/js/localization.spec.js +0 -48
- data/spec/js/numbers.spec.js +0 -170
- data/spec/js/placeholder.spec.js +0 -24
- data/spec/js/pluralization.spec.js +0 -211
- data/spec/js/prepare_options.spec.js +0 -41
- data/spec/js/require.js +0 -2083
- data/spec/js/specs.html +0 -49
- data/spec/js/specs_requirejs.html +0 -72
- data/spec/js/translate.spec.js +0 -284
- data/spec/js/translations.js +0 -163
- data/spec/js/utility_functions.spec.js +0 -20
- data/spec/ruby/i18n/js/fallback_locales_spec.rb +0 -84
- data/spec/ruby/i18n/js/segment_spec.rb +0 -219
- data/spec/ruby/i18n/js/utils_spec.rb +0 -106
- data/spec/ruby/i18n/js_spec.rb +0 -663
- data/spec/spec_helper.rb +0 -79
- data/yarn.lock +0 -131
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>
|
data/spec/js/translate.spec.js
DELETED
@@ -1,284 +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("returns translation for single scope", function(){
|
14
|
-
expect(I18n.t("hello")).toEqual("Hello World!");
|
15
|
-
});
|
16
|
-
|
17
|
-
it("returns translation as object", function(){
|
18
|
-
expect(I18n.t("greetings")).toEqual(I18n.translations.en.greetings);
|
19
|
-
});
|
20
|
-
|
21
|
-
it("returns missing message translation for valid scope with null", function(){
|
22
|
-
actual = I18n.t("null_key");
|
23
|
-
expected = '[missing "en.null_key" translation]';
|
24
|
-
expect(actual).toEqual(expected);
|
25
|
-
});
|
26
|
-
|
27
|
-
it("returns missing message translation for invalid scope", function(){
|
28
|
-
actual = I18n.t("invalid.scope");
|
29
|
-
expected = '[missing "en.invalid.scope" translation]';
|
30
|
-
expect(actual).toEqual(expected);
|
31
|
-
});
|
32
|
-
|
33
|
-
it("returns missing message translation with provided locale for invalid scope", function(){
|
34
|
-
actual = I18n.t("invalid.scope", { locale: "ja" });
|
35
|
-
expected = '[missing "ja.invalid.scope" translation]';
|
36
|
-
expect(actual).toEqual(expected);
|
37
|
-
});
|
38
|
-
|
39
|
-
it("returns guessed translation if missingBehaviour is set to guess", function(){
|
40
|
-
I18n.missingBehaviour = 'guess'
|
41
|
-
actual = I18n.t("invalid.thisIsAutomaticallyGeneratedTranslation");
|
42
|
-
expected = 'this is automatically generated translation';
|
43
|
-
expect(actual).toEqual(expected);
|
44
|
-
});
|
45
|
-
|
46
|
-
it("returns guessed translation with prefix if missingBehaviour is set to guess and prefix is also provided", function(){
|
47
|
-
I18n.missingBehaviour = 'guess'
|
48
|
-
I18n.missingTranslationPrefix = 'EE: '
|
49
|
-
actual = I18n.t("invalid.thisIsAutomaticallyGeneratedTranslation");
|
50
|
-
expected = 'EE: this is automatically generated translation';
|
51
|
-
expect(actual).toEqual(expected);
|
52
|
-
});
|
53
|
-
|
54
|
-
it("returns missing message translation for valid scope with scope", function(){
|
55
|
-
actual = I18n.t("monster", {scope: "greetings"});
|
56
|
-
expected = '[missing "en.greetings.monster" translation]';
|
57
|
-
expect(actual).toEqual(expected);
|
58
|
-
});
|
59
|
-
|
60
|
-
it("returns translation for single scope on a custom locale", function(){
|
61
|
-
I18n.locale = "pt-BR";
|
62
|
-
expect(I18n.t("hello")).toEqual("Olá Mundo!");
|
63
|
-
});
|
64
|
-
|
65
|
-
it("returns translation for multiple scopes", function(){
|
66
|
-
expect(I18n.t("greetings.stranger")).toEqual("Hello stranger!");
|
67
|
-
});
|
68
|
-
|
69
|
-
it("returns translation with default locale option", function(){
|
70
|
-
expect(I18n.t("hello", {locale: "en"})).toEqual("Hello World!");
|
71
|
-
expect(I18n.t("hello", {locale: "pt-BR"})).toEqual("Olá Mundo!");
|
72
|
-
});
|
73
|
-
|
74
|
-
it("fallbacks to the default locale when I18n.fallbacks is enabled", function(){
|
75
|
-
I18n.locale = "pt-BR";
|
76
|
-
I18n.fallbacks = true;
|
77
|
-
expect(I18n.t("greetings.stranger")).toEqual("Hello stranger!");
|
78
|
-
});
|
79
|
-
|
80
|
-
it("fallbacks to default locale when providing an unknown locale", function(){
|
81
|
-
I18n.locale = "fr";
|
82
|
-
I18n.fallbacks = true;
|
83
|
-
expect(I18n.t("greetings.stranger")).toEqual("Hello stranger!");
|
84
|
-
});
|
85
|
-
|
86
|
-
it("fallbacks to less specific locale", function(){
|
87
|
-
I18n.locale = "de-DE";
|
88
|
-
I18n.fallbacks = true;
|
89
|
-
expect(I18n.t("hello")).toEqual("Hallo Welt!");
|
90
|
-
});
|
91
|
-
|
92
|
-
describe("when a 3-part locale is used", function(){
|
93
|
-
beforeEach(function(){
|
94
|
-
I18n.locale = "zh-Hant-TW";
|
95
|
-
I18n.fallbacks = true;
|
96
|
-
});
|
97
|
-
|
98
|
-
it("fallbacks to 2-part locale when absent", function(){
|
99
|
-
expect(I18n.t("cat")).toEqual("貓");
|
100
|
-
});
|
101
|
-
|
102
|
-
it("fallbacks to 1-part locale when 2-part missing requested translation", function(){
|
103
|
-
expect(I18n.t("dog")).toEqual("狗");
|
104
|
-
});
|
105
|
-
|
106
|
-
it("fallbacks to 2-part for the first time", function(){
|
107
|
-
expect(I18n.t("dragon")).toEqual("龍");
|
108
|
-
});
|
109
|
-
});
|
110
|
-
|
111
|
-
it("fallbacks using custom rules (function)", function(){
|
112
|
-
I18n.locale = "no";
|
113
|
-
I18n.fallbacks = true;
|
114
|
-
I18n.locales["no"] = function() {
|
115
|
-
return ["nb"];
|
116
|
-
};
|
117
|
-
|
118
|
-
expect(I18n.t("hello")).toEqual("Hei Verden!");
|
119
|
-
});
|
120
|
-
|
121
|
-
it("fallbacks using custom rules (array)", function() {
|
122
|
-
I18n.locale = "no";
|
123
|
-
I18n.fallbacks = true;
|
124
|
-
I18n.locales["no"] = ["no", "nb"];
|
125
|
-
|
126
|
-
expect(I18n.t("hello")).toEqual("Hei Verden!");
|
127
|
-
});
|
128
|
-
|
129
|
-
it("fallbacks using custom rules (string)", function() {
|
130
|
-
I18n.locale = "no";
|
131
|
-
I18n.fallbacks = true;
|
132
|
-
I18n.locales["no"] = "nb";
|
133
|
-
|
134
|
-
expect(I18n.t("hello")).toEqual("Hei Verden!");
|
135
|
-
});
|
136
|
-
|
137
|
-
describe("when provided default values", function() {
|
138
|
-
it("uses scope provided in defaults if scope doesn't exist", function() {
|
139
|
-
actual = I18n.t("Hello!", {defaults: [{scope: "greetings.stranger"}]});
|
140
|
-
expect(actual).toEqual("Hello stranger!");
|
141
|
-
});
|
142
|
-
|
143
|
-
it("continues to fallback until a scope is found", function() {
|
144
|
-
var defaults = [{scope: "foo"}, {scope: "hello"}];
|
145
|
-
|
146
|
-
actual = I18n.t("foo", {defaults: defaults});
|
147
|
-
expect(actual).toEqual("Hello World!");
|
148
|
-
});
|
149
|
-
|
150
|
-
it("uses message if specified as a default", function() {
|
151
|
-
var defaults = [{message: "Hello all!"}];
|
152
|
-
actual = I18n.t("foo", {defaults: defaults});
|
153
|
-
expect(actual).toEqual("Hello all!");
|
154
|
-
});
|
155
|
-
|
156
|
-
it("uses the first message if no scopes are found", function() {
|
157
|
-
var defaults = [
|
158
|
-
{scope: "bar"}
|
159
|
-
, {message: "Hello all!"}
|
160
|
-
, {scope: "hello"}];
|
161
|
-
actual = I18n.t("foo", {defaults: defaults});
|
162
|
-
expect(actual).toEqual("Hello all!");
|
163
|
-
});
|
164
|
-
|
165
|
-
it("uses default value if no scope is found", function() {
|
166
|
-
var options = {
|
167
|
-
defaults: [{scope: "bar"}]
|
168
|
-
, defaultValue: "Hello all!"
|
169
|
-
};
|
170
|
-
actual = I18n.t("foo", options);
|
171
|
-
expect(actual).toEqual("Hello all!");
|
172
|
-
});
|
173
|
-
|
174
|
-
it("uses default scope over default value if default scope is found", function() {
|
175
|
-
var options = {
|
176
|
-
defaults: [{scope: "hello"}]
|
177
|
-
, defaultValue: "Hello all!"
|
178
|
-
};
|
179
|
-
actual = I18n.t("foo", options);
|
180
|
-
expect(actual).toEqual("Hello World!");
|
181
|
-
})
|
182
|
-
|
183
|
-
it("uses default value with lazy evaluation", function () {
|
184
|
-
var options = {
|
185
|
-
defaults: [{scope: "bar"}]
|
186
|
-
, defaultValue: function(scope) {
|
187
|
-
return scope.toUpperCase();
|
188
|
-
}
|
189
|
-
};
|
190
|
-
actual = I18n.t("foo", options);
|
191
|
-
expect(actual).toEqual("FOO");
|
192
|
-
})
|
193
|
-
|
194
|
-
it("pluralizes using the correct scope if translation is found within default scope", function() {
|
195
|
-
expect(I18n.translations["en"]["mailbox"]).toEqual(undefined);
|
196
|
-
actual = I18n.t("mailbox.inbox", {count: 1, defaults: [{scope: "inbox"}]});
|
197
|
-
expected = I18n.t("inbox", {count: 1})
|
198
|
-
expect(actual).toEqual(expected)
|
199
|
-
})
|
200
|
-
});
|
201
|
-
|
202
|
-
it("uses default value for simple translation", function(){
|
203
|
-
actual = I18n.t("warning", {defaultValue: "Warning!"});
|
204
|
-
expect(actual).toEqual("Warning!");
|
205
|
-
});
|
206
|
-
|
207
|
-
it("uses default value for plural translation", function(){
|
208
|
-
actual = I18n.t("message", {defaultValue: { one: '%{count} message', other: '%{count} messages'}, count: 1});
|
209
|
-
expect(actual).toEqual("1 message");
|
210
|
-
});
|
211
|
-
|
212
|
-
it("uses default value for unknown locale", function(){
|
213
|
-
I18n.locale = "fr";
|
214
|
-
actual = I18n.t("warning", {defaultValue: "Warning!"});
|
215
|
-
expect(actual).toEqual("Warning!");
|
216
|
-
});
|
217
|
-
|
218
|
-
it("uses default value with interpolation", function(){
|
219
|
-
actual = I18n.t(
|
220
|
-
"alert",
|
221
|
-
{defaultValue: "Attention! {{message}}", message: "You're out of quota!"}
|
222
|
-
);
|
223
|
-
|
224
|
-
expect(actual).toEqual("Attention! You're out of quota!");
|
225
|
-
});
|
226
|
-
|
227
|
-
it("ignores default value when scope exists", function(){
|
228
|
-
actual = I18n.t("hello", {defaultValue: "What's up?"});
|
229
|
-
expect(actual).toEqual("Hello World!");
|
230
|
-
});
|
231
|
-
|
232
|
-
it("returns translation for custom scope separator", function(){
|
233
|
-
I18n.defaultSeparator = "•";
|
234
|
-
actual = I18n.t("greetings•stranger");
|
235
|
-
expect(actual).toEqual("Hello stranger!");
|
236
|
-
});
|
237
|
-
|
238
|
-
it("returns boolean values", function() {
|
239
|
-
expect(I18n.t("booleans.yes")).toEqual(true);
|
240
|
-
expect(I18n.t("booleans.no")).toEqual(false);
|
241
|
-
});
|
242
|
-
|
243
|
-
it("escapes $ when doing substitution (IE)", function(){
|
244
|
-
I18n.locale = "en";
|
245
|
-
|
246
|
-
expect(I18n.t("paid", {price: "$0"})).toEqual("You were paid $0");
|
247
|
-
expect(I18n.t("paid", {price: "$0.12"})).toEqual("You were paid $0.12");
|
248
|
-
expect(I18n.t("paid", {price: "$1.35"})).toEqual("You were paid $1.35");
|
249
|
-
});
|
250
|
-
|
251
|
-
it("replaces all occurrences of escaped $", function(){
|
252
|
-
I18n.locale = "en";
|
253
|
-
|
254
|
-
expect(I18n.t("paid_with_vat", {
|
255
|
-
price: "$0.12",
|
256
|
-
vat: "$0.02"}
|
257
|
-
)).toEqual("You were paid $0.12 (incl. VAT $0.02)");
|
258
|
-
});
|
259
|
-
|
260
|
-
it("sets default scope", function(){
|
261
|
-
var options = {scope: "greetings"};
|
262
|
-
expect(I18n.t("stranger", options)).toEqual("Hello stranger!");
|
263
|
-
});
|
264
|
-
|
265
|
-
it("accepts the scope as an array", function(){
|
266
|
-
expect(I18n.t(["greetings", "stranger"])).toEqual("Hello stranger!");
|
267
|
-
});
|
268
|
-
|
269
|
-
it("accepts the scope as an array using a base scope", function(){
|
270
|
-
expect(I18n.t(["stranger"], {scope: "greetings"})).toEqual("Hello stranger!");
|
271
|
-
});
|
272
|
-
|
273
|
-
it("returns an array with values interpolated", function(){
|
274
|
-
var options = {value: 314};
|
275
|
-
expect(I18n.t("arrayWithParams", options)).toEqual([
|
276
|
-
null,
|
277
|
-
"An item with a param of " + options.value,
|
278
|
-
"Another item with a param of " + options.value,
|
279
|
-
"A last item with a param of " + options.value,
|
280
|
-
["An", "array", "of", "strings"],
|
281
|
-
{foo: "bar"}
|
282
|
-
]);
|
283
|
-
});
|
284
|
-
});
|
data/spec/js/translations.js
DELETED
@@ -1,163 +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
|
-
, arrayWithParams: [
|
62
|
-
null,
|
63
|
-
"An item with a param of {{value}}",
|
64
|
-
"Another item with a param of {{value}}",
|
65
|
-
"A last item with a param of {{value}}",
|
66
|
-
["An", "array", "of", "strings"],
|
67
|
-
{foo: "bar"}
|
68
|
-
]
|
69
|
-
|
70
|
-
, null_key: null
|
71
|
-
};
|
72
|
-
|
73
|
-
Translations["en-US"] = {
|
74
|
-
date: {
|
75
|
-
formats: {
|
76
|
-
"default": "%d/%m/%Y"
|
77
|
-
, "short": "%d de %B"
|
78
|
-
, "long": "%d de %B de %Y"
|
79
|
-
}
|
80
|
-
|
81
|
-
, day_names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
82
|
-
, abbr_day_names: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
|
83
|
-
, month_names: [null, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
|
84
|
-
, abbr_month_names: [null, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"]
|
85
|
-
, meridian: ["am", "pm"]
|
86
|
-
}
|
87
|
-
};
|
88
|
-
|
89
|
-
Translations["pt-BR"] = {
|
90
|
-
hello: "Olá Mundo!"
|
91
|
-
|
92
|
-
, number: {
|
93
|
-
percentage: {
|
94
|
-
format: {
|
95
|
-
delimiter: ""
|
96
|
-
, separator: ","
|
97
|
-
, precision: 2
|
98
|
-
}
|
99
|
-
}
|
100
|
-
}
|
101
|
-
|
102
|
-
, date: {
|
103
|
-
formats: {
|
104
|
-
"default": "%d/%m/%Y"
|
105
|
-
, "short": "%d de %B"
|
106
|
-
, "long": "%d de %B de %Y"
|
107
|
-
, "short_with_placeholders": "%d de %B {{p1}} {{p2}}"
|
108
|
-
}
|
109
|
-
, day_names: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"]
|
110
|
-
, abbr_day_names: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"]
|
111
|
-
, month_names: [null, "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]
|
112
|
-
, abbr_month_names: [null, "Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"]
|
113
|
-
}
|
114
|
-
|
115
|
-
, time: {
|
116
|
-
formats: {
|
117
|
-
"default": "%A, %d de %B de %Y, %H:%M h"
|
118
|
-
, "short": "%d/%m, %H:%M h"
|
119
|
-
, "long": "%A, %d de %B de %Y, %H:%M h"
|
120
|
-
, "short_with_placeholders": "%d/%m, %H:%M h {{p1}}"
|
121
|
-
}
|
122
|
-
, am: "AM"
|
123
|
-
, pm: "PM"
|
124
|
-
}
|
125
|
-
};
|
126
|
-
|
127
|
-
Translations["de"] = {
|
128
|
-
hello: "Hallo Welt!"
|
129
|
-
, date: {
|
130
|
-
day_names: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"]
|
131
|
-
}
|
132
|
-
|
133
|
-
, time: {
|
134
|
-
am: "de:AM"
|
135
|
-
, pm: "de:PM"
|
136
|
-
}
|
137
|
-
};
|
138
|
-
|
139
|
-
Translations["nb"] = {
|
140
|
-
hello: "Hei Verden!"
|
141
|
-
};
|
142
|
-
|
143
|
-
Translations["zh-Hant"] = {
|
144
|
-
cat: "貓"
|
145
|
-
, dragon: "龍"
|
146
|
-
};
|
147
|
-
|
148
|
-
Translations["zh"] = {
|
149
|
-
dog: "狗"
|
150
|
-
, dragon: "龙"
|
151
|
-
};
|
152
|
-
|
153
|
-
return Translations;
|
154
|
-
};
|
155
|
-
|
156
|
-
if (typeof define === 'function' && define.amd) {
|
157
|
-
define(function() { return generator; });
|
158
|
-
} else if (typeof(exports) === "undefined") {
|
159
|
-
window.Translations = generator;
|
160
|
-
} else {
|
161
|
-
module.exports = generator;
|
162
|
-
}
|
163
|
-
})();
|
@@ -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
|
-
});
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe I18n::JS::FallbackLocales do
|
4
|
-
let(:locale) { :fr }
|
5
|
-
let(:default_locale) { :en }
|
6
|
-
|
7
|
-
describe "#locales" do
|
8
|
-
let(:fallbacks_locales) { described_class.new(fallbacks, locale) }
|
9
|
-
subject { fallbacks_locales.locales }
|
10
|
-
|
11
|
-
let(:fetching_locales) { proc do fallbacks_locales.locales end }
|
12
|
-
|
13
|
-
context "when given true as fallbacks" do
|
14
|
-
let(:fallbacks) { true }
|
15
|
-
it { should eq([default_locale]) }
|
16
|
-
end
|
17
|
-
|
18
|
-
context "when given false as fallbacks" do
|
19
|
-
let(:fallbacks) { false }
|
20
|
-
it { expect(fetching_locales).to raise_error(ArgumentError) }
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when given a valid locale as fallbacks" do
|
24
|
-
let(:fallbacks) { :de }
|
25
|
-
it { should eq([:de]) }
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when given a valid Array as fallbacks" do
|
29
|
-
let(:fallbacks) { [:de, :en] }
|
30
|
-
it { should eq([:de, :en]) }
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when given a valid Hash with current locale as key as fallbacks" do
|
34
|
-
let(:fallbacks) do { :fr => [:de, :en] } end
|
35
|
-
it { should eq([:de, :en]) }
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when given a valid Hash without current locale as key as fallbacks" do
|
39
|
-
let(:fallbacks) do { :de => [:fr, :en] } end
|
40
|
-
it { should eq([default_locale]) }
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when given a invalid locale as fallbacks" do
|
44
|
-
let(:fallbacks) { :invalid_locale }
|
45
|
-
it { should eq([:invalid_locale]) }
|
46
|
-
end
|
47
|
-
|
48
|
-
context "when given a invalid type as fallbacks" do
|
49
|
-
let(:fallbacks) { 42 }
|
50
|
-
it { expect(fetching_locales).to raise_error(ArgumentError) }
|
51
|
-
end
|
52
|
-
|
53
|
-
# I18n::Backend::Fallbacks
|
54
|
-
context "when I18n::Backend::Fallbacks is used" do
|
55
|
-
let(:backend_with_fallbacks) { backend_class_with_fallbacks.new }
|
56
|
-
|
57
|
-
before do
|
58
|
-
I18n::JS.backend = backend_with_fallbacks
|
59
|
-
I18n.fallbacks[:fr] = [:de, :en]
|
60
|
-
end
|
61
|
-
after { I18n::JS.backend = I18n::Backend::Simple.new }
|
62
|
-
|
63
|
-
context "given true as fallbacks" do
|
64
|
-
let(:fallbacks) { true }
|
65
|
-
it { should eq([:de, :en]) }
|
66
|
-
end
|
67
|
-
|
68
|
-
context "given :default_locale as fallbacks" do
|
69
|
-
let(:fallbacks) { :default_locale }
|
70
|
-
it { should eq([:en]) }
|
71
|
-
end
|
72
|
-
|
73
|
-
context "given a Hash with current locale as fallbacks" do
|
74
|
-
let(:fallbacks) do { :fr => [:en] } end
|
75
|
-
it { should eq([:en]) }
|
76
|
-
end
|
77
|
-
|
78
|
-
context "given a Hash without current locale as fallbacks" do
|
79
|
-
let(:fallbacks) do { :de => [:en] } end
|
80
|
-
it { should eq([:de, :en]) }
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|