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.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +4 -0
- data/.github/FUNDING.yml +1 -1
- data/.github/ISSUE_TEMPLATE/bug_report.md +41 -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 +61 -0
- data/.gitignore +11 -7
- data/.rubocop.yml +12 -0
- data/CHANGELOG.md +12 -571
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +86 -1043
- data/Rakefile +10 -20
- data/exe/i18n +5 -0
- data/i18n-js.gemspec +47 -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 +78 -0
- data/lib/i18n-js/cli/command.rb +43 -0
- data/lib/i18n-js/cli/export_command.rb +108 -0
- data/lib/i18n-js/cli/init_command.rb +50 -0
- data/lib/i18n-js/cli/ui.rb +30 -0
- data/lib/i18n-js/cli/version_command.rb +18 -0
- data/lib/i18n-js/cli.rb +47 -0
- data/lib/i18n-js/listen.rb +80 -0
- data/lib/i18n-js/schema.rb +92 -0
- data/lib/i18n-js/version.rb +5 -0
- data/lib/i18n-js.rb +66 -1
- metadata +125 -201
- data/.editorconfig +0 -24
- data/.github/workflows/tests.yaml +0 -106
- data/.npmignore +0 -27
- data/Appraisals +0 -52
- data/app/assets/javascripts/i18n/filtered.js.erb +0 -23
- data/app/assets/javascripts/i18n/shims.js +0 -240
- data/app/assets/javascripts/i18n/translations.js +0 -3
- data/app/assets/javascripts/i18n.js +0 -1095
- 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_10.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/gemfiles/i18n_1_6.gemfile +0 -7
- data/gemfiles/i18n_1_7.gemfile +0 -7
- data/gemfiles/i18n_1_8.gemfile +0 -7
- data/gemfiles/i18n_1_9.gemfile +0 -7
- data/i18njs.png +0 -0
- data/lib/i18n/js/dependencies.rb +0 -67
- 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 -25
- data/lib/i18n/js/formatters/js.rb +0 -39
- data/lib/i18n/js/formatters/json.rb +0 -13
- data/lib/i18n/js/middleware.rb +0 -82
- data/lib/i18n/js/private/config_store.rb +0 -31
- data/lib/i18n/js/private/hash_with_symbol_keys.rb +0 -36
- data/lib/i18n/js/segment.rb +0 -81
- data/lib/i18n/js/utils.rb +0 -91
- data/lib/i18n/js/version.rb +0 -7
- data/lib/i18n/js.rb +0 -274
- 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/package.json +0 -25
- 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_available_locales_custom.yml +0 -1
- 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_prefix_and_pretty_print.yml +0 -9
- 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 -133
- data/spec/fixtures/merge_plurals.yml +0 -6
- data/spec/fixtures/merge_plurals_with_no_overrides.yml +0 -4
- data/spec/fixtures/merge_plurals_with_partial_overrides.yml +0 -4
- data/spec/fixtures/millions.yml +0 -4
- 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 -276
- 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/json_parsable.spec.js +0 -14
- data/spec/js/locales.spec.js +0 -31
- data/spec/js/localization.spec.js +0 -78
- data/spec/js/numbers.spec.js +0 -174
- data/spec/js/placeholder.spec.js +0 -24
- data/spec/js/pluralization.spec.js +0 -228
- 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 -304
- data/spec/js/translations.js +0 -188
- 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 -286
- data/spec/ruby/i18n/js/utils_spec.rb +0 -138
- data/spec/ruby/i18n/js_spec.rb +0 -797
- data/spec/spec_helper.rb +0 -80
- 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>
|
data/spec/js/translate.spec.js
DELETED
@@ -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
|
-
});
|
data/spec/js/translations.js
DELETED
@@ -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
|
-
});
|