i18n-js 3.5.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -1
- data/app/assets/javascripts/i18n.js +3 -3
- data/app/assets/javascripts/i18n/shims.js +32 -0
- data/lib/i18n/js/version.rb +1 -1
- data/package.json +1 -1
- data/spec/js/localization.spec.js +24 -14
- data/spec/js/pluralization.spec.js +10 -2
- data/spec/js/translate.spec.js +56 -46
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62051e50266fb55f81099456051f21393aba9a4ecabda1bf2739ae181bf64ec6
|
4
|
+
data.tar.gz: 517cc9090a03e060781be401588b00495a18ccf934fd155ec838d1334b349d7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e88fc0e5f91b673a401310c1b8db1bc5f04a3d3cf5379d978fda9a1030cb5bedb897175577301b5cd4ef86cd025f03c17250c1d5953c7779a48a0911339e7307
|
7
|
+
data.tar.gz: b7caf39eff008a7817a512f60edffc515a3baa41ff8c7388d54f8fcd59f42e9247ee28567f58c264a319fd9f7049712fc8d0a76a85ca778dad4d70144fb4124f
|
data/CHANGELOG.md
CHANGED
@@ -18,6 +18,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
18
18
|
- Nothing
|
19
19
|
|
20
20
|
|
21
|
+
## [3.5.1] - 2019-12-21
|
22
|
+
|
23
|
+
### Changed
|
24
|
+
|
25
|
+
- [JS] Bound shortcut functions
|
26
|
+
(PR: https://github.com/fnando/i18n-js/pull/560)
|
27
|
+
|
28
|
+
|
21
29
|
## [3.5.0] - 2019-11-12
|
22
30
|
|
23
31
|
### Added
|
@@ -433,7 +441,8 @@ And today is not April Fools' Day
|
|
433
441
|
|
434
442
|
|
435
443
|
|
436
|
-
[Unreleased]: https://github.com/fnando/i18n-js/compare/v3.5.
|
444
|
+
[Unreleased]: https://github.com/fnando/i18n-js/compare/v3.5.1...HEAD
|
445
|
+
[3.5.1]: https://github.com/fnando/i18n-js/compare/v3.5.0...v3.5.1
|
437
446
|
[3.5.0]: https://github.com/fnando/i18n-js/compare/v3.4.2...v3.5.0
|
438
447
|
[3.4.2]: https://github.com/fnando/i18n-js/compare/v3.4.1...v3.4.2
|
439
448
|
[3.4.1]: https://github.com/fnando/i18n-js/compare/v3.4.0...v3.4.1
|
@@ -1084,9 +1084,9 @@
|
|
1084
1084
|
};
|
1085
1085
|
|
1086
1086
|
// Set aliases, so we can save some typing.
|
1087
|
-
I18n.t = I18n.translate;
|
1088
|
-
I18n.l = I18n.localize;
|
1089
|
-
I18n.p = I18n.pluralize;
|
1087
|
+
I18n.t = I18n.translate.bind(I18n);
|
1088
|
+
I18n.l = I18n.localize.bind(I18n);
|
1089
|
+
I18n.p = I18n.pluralize.bind(I18n);
|
1090
1090
|
|
1091
1091
|
return I18n;
|
1092
1092
|
}));
|
@@ -206,3 +206,35 @@ if (!Array.prototype.map) {
|
|
206
206
|
return A;
|
207
207
|
};
|
208
208
|
}
|
209
|
+
|
210
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind
|
211
|
+
if (!Function.prototype.bind) (function(){
|
212
|
+
var ArrayPrototypeSlice = Array.prototype.slice;
|
213
|
+
Function.prototype.bind = function(otherThis) {
|
214
|
+
if (typeof this !== 'function') {
|
215
|
+
// closest thing possible to the ECMAScript 5
|
216
|
+
// internal IsCallable function
|
217
|
+
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
|
218
|
+
}
|
219
|
+
|
220
|
+
var baseArgs= ArrayPrototypeSlice .call(arguments, 1),
|
221
|
+
baseArgsLength = baseArgs.length,
|
222
|
+
fToBind = this,
|
223
|
+
fNOP = function() {},
|
224
|
+
fBound = function() {
|
225
|
+
baseArgs.length = baseArgsLength; // reset to default base arguments
|
226
|
+
baseArgs.push.apply(baseArgs, arguments);
|
227
|
+
return fToBind.apply(
|
228
|
+
fNOP.prototype.isPrototypeOf(this) ? this : otherThis, baseArgs
|
229
|
+
);
|
230
|
+
};
|
231
|
+
|
232
|
+
if (this.prototype) {
|
233
|
+
// Function.prototype doesn't have a prototype property
|
234
|
+
fNOP.prototype = this.prototype;
|
235
|
+
}
|
236
|
+
fBound.prototype = new fNOP();
|
237
|
+
|
238
|
+
return fBound;
|
239
|
+
};
|
240
|
+
})();
|
data/lib/i18n/js/version.rb
CHANGED
data/package.json
CHANGED
@@ -10,45 +10,55 @@ describe("Localization", function(){
|
|
10
10
|
I18n.translations = Translations();
|
11
11
|
});
|
12
12
|
|
13
|
+
it("sets bound alias", function() {
|
14
|
+
expect(I18n.l).toEqual(jasmine.any(Function));
|
15
|
+
expect(I18n.l).not.toBe(I18n.localize);
|
16
|
+
});
|
17
|
+
|
13
18
|
it("localizes number", function(){
|
14
|
-
expect(I18n.
|
19
|
+
expect(I18n.localize("number", 1234567)).toEqual("1,234,567.000");
|
20
|
+
});
|
21
|
+
|
22
|
+
it("localizes number with 'l' shortcut", function(){
|
23
|
+
var l = I18n.l;
|
24
|
+
expect(l("number", 1234567)).toEqual("1,234,567.000");
|
15
25
|
});
|
16
26
|
|
17
27
|
it("localizes currency", function(){
|
18
|
-
expect(I18n.
|
28
|
+
expect(I18n.localize("currency", 1234567)).toEqual("$1,234,567.00");
|
19
29
|
});
|
20
30
|
|
21
31
|
it("localizes date strings", function(){
|
22
32
|
I18n.locale = "pt-BR";
|
23
33
|
|
24
|
-
expect(I18n.
|
25
|
-
expect(I18n.
|
26
|
-
expect(I18n.
|
34
|
+
expect(I18n.localize("date.formats.default", "2009-11-29")).toEqual("29/11/2009");
|
35
|
+
expect(I18n.localize("date.formats.short", "2009-01-07")).toEqual("07 de Janeiro");
|
36
|
+
expect(I18n.localize("date.formats.long", "2009-01-07")).toEqual("07 de Janeiro de 2009");
|
27
37
|
});
|
28
38
|
|
29
39
|
it("localizes time strings", function(){
|
30
40
|
I18n.locale = "pt-BR";
|
31
41
|
|
32
|
-
expect(I18n.
|
33
|
-
expect(I18n.
|
34
|
-
expect(I18n.
|
42
|
+
expect(I18n.localize("time.formats.default", "2009-11-29 15:07:59")).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
|
43
|
+
expect(I18n.localize("time.formats.short", "2009-01-07 09:12:35")).toEqual("07/01, 09:12 h");
|
44
|
+
expect(I18n.localize("time.formats.long", "2009-11-29 15:07:59")).toEqual("Domingo, 29 de Novembro de 2009, 15:07 h");
|
35
45
|
});
|
36
46
|
|
37
47
|
it("return 'Invalid Date' or original value for invalid input", function(){
|
38
|
-
expect(I18n.
|
39
|
-
expect(I18n.
|
40
|
-
expect(I18n.
|
48
|
+
expect(I18n.localize("time.formats.default", "")).toEqual("Invalid Date");
|
49
|
+
expect(I18n.localize("time.formats.default", null)).toEqual(null);
|
50
|
+
expect(I18n.localize("time.formats.default", undefined)).toEqual(undefined);
|
41
51
|
});
|
42
52
|
|
43
53
|
it("localizes date/time strings with placeholders", function(){
|
44
54
|
I18n.locale = "pt-BR";
|
45
55
|
|
46
|
-
expect(I18n.
|
47
|
-
expect(I18n.
|
56
|
+
expect(I18n.localize("date.formats.short_with_placeholders", "2009-01-07", { p1: "!", p2: "?" })).toEqual("07 de Janeiro ! ?");
|
57
|
+
expect(I18n.localize("time.formats.short_with_placeholders", "2009-01-07 09:12:35", { p1: "!" })).toEqual("07/01, 09:12 h !");
|
48
58
|
});
|
49
59
|
|
50
60
|
it("localizes percentage", function(){
|
51
61
|
I18n.locale = "pt-BR";
|
52
|
-
expect(I18n.
|
62
|
+
expect(I18n.localize("percentage", 123.45)).toEqual("123,45%");
|
53
63
|
});
|
54
64
|
});
|
@@ -10,8 +10,9 @@ describe("Pluralization", function(){
|
|
10
10
|
I18n.translations = Translations();
|
11
11
|
});
|
12
12
|
|
13
|
-
it("sets alias", function() {
|
14
|
-
expect(I18n.p).toEqual(
|
13
|
+
it("sets bound alias", function() {
|
14
|
+
expect(I18n.p).toEqual(jasmine.any(Function));
|
15
|
+
expect(I18n.p).not.toBe(I18n.pluralize);
|
15
16
|
});
|
16
17
|
|
17
18
|
it("pluralizes scope", function(){
|
@@ -20,6 +21,13 @@ describe("Pluralization", function(){
|
|
20
21
|
expect(I18n.p(5, "inbox")).toEqual("You have 5 messages");
|
21
22
|
});
|
22
23
|
|
24
|
+
it("pluralizes scope with 'p' shortcut", function(){
|
25
|
+
var p = I18n.p;
|
26
|
+
expect(p(0, "inbox")).toEqual("You have no messages");
|
27
|
+
expect(p(1, "inbox")).toEqual("You have 1 message");
|
28
|
+
expect(p(5, "inbox")).toEqual("You have 5 messages");
|
29
|
+
});
|
30
|
+
|
23
31
|
it("pluralizes using the 'other' scope", function(){
|
24
32
|
I18n.translations["en"]["inbox"]["zero"] = null;
|
25
33
|
expect(I18n.p(0, "inbox")).toEqual("You have 0 messages");
|
data/spec/js/translate.spec.js
CHANGED
@@ -10,35 +10,45 @@ describe("Translate", function(){
|
|
10
10
|
I18n.translations = Translations();
|
11
11
|
});
|
12
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
|
+
|
13
18
|
it("returns translation for single scope", function(){
|
14
|
-
expect(I18n.
|
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!");
|
15
25
|
});
|
16
26
|
|
17
27
|
it("returns translation as object", function(){
|
18
|
-
expect(I18n.
|
28
|
+
expect(I18n.translate("greetings")).toEqual(I18n.translations.en.greetings);
|
19
29
|
});
|
20
30
|
|
21
31
|
it("returns missing message translation for valid scope with null", function(){
|
22
|
-
actual = I18n.
|
32
|
+
actual = I18n.translate("null_key");
|
23
33
|
expected = '[missing "en.null_key" translation]';
|
24
34
|
expect(actual).toEqual(expected);
|
25
35
|
});
|
26
36
|
|
27
37
|
it("returns missing message translation for invalid scope", function(){
|
28
|
-
actual = I18n.
|
38
|
+
actual = I18n.translate("invalid.scope");
|
29
39
|
expected = '[missing "en.invalid.scope" translation]';
|
30
40
|
expect(actual).toEqual(expected);
|
31
41
|
});
|
32
42
|
|
33
43
|
it("returns missing message translation with provided locale for invalid scope", function(){
|
34
|
-
actual = I18n.
|
44
|
+
actual = I18n.translate("invalid.scope", { locale: "ja" });
|
35
45
|
expected = '[missing "ja.invalid.scope" translation]';
|
36
46
|
expect(actual).toEqual(expected);
|
37
47
|
});
|
38
48
|
|
39
49
|
it("returns guessed translation if missingBehaviour is set to guess", function(){
|
40
50
|
I18n.missingBehaviour = 'guess'
|
41
|
-
actual = I18n.
|
51
|
+
actual = I18n.translate("invalid.thisIsAutomaticallyGeneratedTranslation");
|
42
52
|
expected = 'this is automatically generated translation';
|
43
53
|
expect(actual).toEqual(expected);
|
44
54
|
});
|
@@ -46,47 +56,47 @@ describe("Translate", function(){
|
|
46
56
|
it("returns guessed translation with prefix if missingBehaviour is set to guess and prefix is also provided", function(){
|
47
57
|
I18n.missingBehaviour = 'guess'
|
48
58
|
I18n.missingTranslationPrefix = 'EE: '
|
49
|
-
actual = I18n.
|
59
|
+
actual = I18n.translate("invalid.thisIsAutomaticallyGeneratedTranslation");
|
50
60
|
expected = 'EE: this is automatically generated translation';
|
51
61
|
expect(actual).toEqual(expected);
|
52
62
|
});
|
53
63
|
|
54
64
|
it("returns missing message translation for valid scope with scope", function(){
|
55
|
-
actual = I18n.
|
65
|
+
actual = I18n.translate("monster", {scope: "greetings"});
|
56
66
|
expected = '[missing "en.greetings.monster" translation]';
|
57
67
|
expect(actual).toEqual(expected);
|
58
68
|
});
|
59
69
|
|
60
70
|
it("returns translation for single scope on a custom locale", function(){
|
61
71
|
I18n.locale = "pt-BR";
|
62
|
-
expect(I18n.
|
72
|
+
expect(I18n.translate("hello")).toEqual("Olá Mundo!");
|
63
73
|
});
|
64
74
|
|
65
75
|
it("returns translation for multiple scopes", function(){
|
66
|
-
expect(I18n.
|
76
|
+
expect(I18n.translate("greetings.stranger")).toEqual("Hello stranger!");
|
67
77
|
});
|
68
78
|
|
69
79
|
it("returns translation with default locale option", function(){
|
70
|
-
expect(I18n.
|
71
|
-
expect(I18n.
|
80
|
+
expect(I18n.translate("hello", {locale: "en"})).toEqual("Hello World!");
|
81
|
+
expect(I18n.translate("hello", {locale: "pt-BR"})).toEqual("Olá Mundo!");
|
72
82
|
});
|
73
83
|
|
74
84
|
it("fallbacks to the default locale when I18n.fallbacks is enabled", function(){
|
75
85
|
I18n.locale = "pt-BR";
|
76
86
|
I18n.fallbacks = true;
|
77
|
-
expect(I18n.
|
87
|
+
expect(I18n.translate("greetings.stranger")).toEqual("Hello stranger!");
|
78
88
|
});
|
79
89
|
|
80
90
|
it("fallbacks to default locale when providing an unknown locale", function(){
|
81
91
|
I18n.locale = "fr";
|
82
92
|
I18n.fallbacks = true;
|
83
|
-
expect(I18n.
|
93
|
+
expect(I18n.translate("greetings.stranger")).toEqual("Hello stranger!");
|
84
94
|
});
|
85
95
|
|
86
96
|
it("fallbacks to less specific locale", function(){
|
87
97
|
I18n.locale = "de-DE";
|
88
98
|
I18n.fallbacks = true;
|
89
|
-
expect(I18n.
|
99
|
+
expect(I18n.translate("hello")).toEqual("Hallo Welt!");
|
90
100
|
});
|
91
101
|
|
92
102
|
describe("when a 3-part locale is used", function(){
|
@@ -96,15 +106,15 @@ describe("Translate", function(){
|
|
96
106
|
});
|
97
107
|
|
98
108
|
it("fallbacks to 2-part locale when absent", function(){
|
99
|
-
expect(I18n.
|
109
|
+
expect(I18n.translate("cat")).toEqual("貓");
|
100
110
|
});
|
101
111
|
|
102
112
|
it("fallbacks to 1-part locale when 2-part missing requested translation", function(){
|
103
|
-
expect(I18n.
|
113
|
+
expect(I18n.translate("dog")).toEqual("狗");
|
104
114
|
});
|
105
115
|
|
106
116
|
it("fallbacks to 2-part for the first time", function(){
|
107
|
-
expect(I18n.
|
117
|
+
expect(I18n.translate("dragon")).toEqual("龍");
|
108
118
|
});
|
109
119
|
});
|
110
120
|
|
@@ -115,7 +125,7 @@ describe("Translate", function(){
|
|
115
125
|
return ["nb"];
|
116
126
|
};
|
117
127
|
|
118
|
-
expect(I18n.
|
128
|
+
expect(I18n.translate("hello")).toEqual("Hei Verden!");
|
119
129
|
});
|
120
130
|
|
121
131
|
it("fallbacks using custom rules (array)", function() {
|
@@ -123,7 +133,7 @@ describe("Translate", function(){
|
|
123
133
|
I18n.fallbacks = true;
|
124
134
|
I18n.locales["no"] = ["no", "nb"];
|
125
135
|
|
126
|
-
expect(I18n.
|
136
|
+
expect(I18n.translate("hello")).toEqual("Hei Verden!");
|
127
137
|
});
|
128
138
|
|
129
139
|
it("fallbacks using custom rules (string)", function() {
|
@@ -131,25 +141,25 @@ describe("Translate", function(){
|
|
131
141
|
I18n.fallbacks = true;
|
132
142
|
I18n.locales["no"] = "nb";
|
133
143
|
|
134
|
-
expect(I18n.
|
144
|
+
expect(I18n.translate("hello")).toEqual("Hei Verden!");
|
135
145
|
});
|
136
146
|
|
137
147
|
describe("when provided default values", function() {
|
138
148
|
it("uses scope provided in defaults if scope doesn't exist", function() {
|
139
|
-
actual = I18n.
|
149
|
+
actual = I18n.translate("Hello!", {defaults: [{scope: "greetings.stranger"}]});
|
140
150
|
expect(actual).toEqual("Hello stranger!");
|
141
151
|
});
|
142
152
|
|
143
153
|
it("continues to fallback until a scope is found", function() {
|
144
154
|
var defaults = [{scope: "foo"}, {scope: "hello"}];
|
145
155
|
|
146
|
-
actual = I18n.
|
156
|
+
actual = I18n.translate("foo", {defaults: defaults});
|
147
157
|
expect(actual).toEqual("Hello World!");
|
148
158
|
});
|
149
159
|
|
150
160
|
it("uses message if specified as a default", function() {
|
151
161
|
var defaults = [{message: "Hello all!"}];
|
152
|
-
actual = I18n.
|
162
|
+
actual = I18n.translate("foo", {defaults: defaults});
|
153
163
|
expect(actual).toEqual("Hello all!");
|
154
164
|
});
|
155
165
|
|
@@ -158,7 +168,7 @@ describe("Translate", function(){
|
|
158
168
|
{scope: "bar"}
|
159
169
|
, {message: "Hello all!"}
|
160
170
|
, {scope: "hello"}];
|
161
|
-
actual = I18n.
|
171
|
+
actual = I18n.translate("foo", {defaults: defaults});
|
162
172
|
expect(actual).toEqual("Hello all!");
|
163
173
|
});
|
164
174
|
|
@@ -167,7 +177,7 @@ describe("Translate", function(){
|
|
167
177
|
defaults: [{scope: "bar"}]
|
168
178
|
, defaultValue: "Hello all!"
|
169
179
|
};
|
170
|
-
actual = I18n.
|
180
|
+
actual = I18n.translate("foo", options);
|
171
181
|
expect(actual).toEqual("Hello all!");
|
172
182
|
});
|
173
183
|
|
@@ -176,7 +186,7 @@ describe("Translate", function(){
|
|
176
186
|
defaults: [{scope: "hello"}]
|
177
187
|
, defaultValue: "Hello all!"
|
178
188
|
};
|
179
|
-
actual = I18n.
|
189
|
+
actual = I18n.translate("foo", options);
|
180
190
|
expect(actual).toEqual("Hello World!");
|
181
191
|
})
|
182
192
|
|
@@ -187,36 +197,36 @@ describe("Translate", function(){
|
|
187
197
|
return scope.toUpperCase();
|
188
198
|
}
|
189
199
|
};
|
190
|
-
actual = I18n.
|
200
|
+
actual = I18n.translate("foo", options);
|
191
201
|
expect(actual).toEqual("FOO");
|
192
202
|
})
|
193
203
|
|
194
204
|
it("pluralizes using the correct scope if translation is found within default scope", function() {
|
195
205
|
expect(I18n.translations["en"]["mailbox"]).toEqual(undefined);
|
196
|
-
actual = I18n.
|
197
|
-
expected = I18n.
|
206
|
+
actual = I18n.translate("mailbox.inbox", {count: 1, defaults: [{scope: "inbox"}]});
|
207
|
+
expected = I18n.translate("inbox", {count: 1})
|
198
208
|
expect(actual).toEqual(expected)
|
199
209
|
})
|
200
210
|
});
|
201
211
|
|
202
212
|
it("uses default value for simple translation", function(){
|
203
|
-
actual = I18n.
|
213
|
+
actual = I18n.translate("warning", {defaultValue: "Warning!"});
|
204
214
|
expect(actual).toEqual("Warning!");
|
205
215
|
});
|
206
216
|
|
207
217
|
it("uses default value for plural translation", function(){
|
208
|
-
actual = I18n.
|
218
|
+
actual = I18n.translate("message", {defaultValue: { one: '%{count} message', other: '%{count} messages'}, count: 1});
|
209
219
|
expect(actual).toEqual("1 message");
|
210
220
|
});
|
211
221
|
|
212
222
|
it("uses default value for unknown locale", function(){
|
213
223
|
I18n.locale = "fr";
|
214
|
-
actual = I18n.
|
224
|
+
actual = I18n.translate("warning", {defaultValue: "Warning!"});
|
215
225
|
expect(actual).toEqual("Warning!");
|
216
226
|
});
|
217
227
|
|
218
228
|
it("uses default value with interpolation", function(){
|
219
|
-
actual = I18n.
|
229
|
+
actual = I18n.translate(
|
220
230
|
"alert",
|
221
231
|
{defaultValue: "Attention! {{message}}", message: "You're out of quota!"}
|
222
232
|
);
|
@@ -225,33 +235,33 @@ describe("Translate", function(){
|
|
225
235
|
});
|
226
236
|
|
227
237
|
it("ignores default value when scope exists", function(){
|
228
|
-
actual = I18n.
|
238
|
+
actual = I18n.translate("hello", {defaultValue: "What's up?"});
|
229
239
|
expect(actual).toEqual("Hello World!");
|
230
240
|
});
|
231
241
|
|
232
242
|
it("returns translation for custom scope separator", function(){
|
233
243
|
I18n.defaultSeparator = "•";
|
234
|
-
actual = I18n.
|
244
|
+
actual = I18n.translate("greetings•stranger");
|
235
245
|
expect(actual).toEqual("Hello stranger!");
|
236
246
|
});
|
237
247
|
|
238
248
|
it("returns boolean values", function() {
|
239
|
-
expect(I18n.
|
240
|
-
expect(I18n.
|
249
|
+
expect(I18n.translate("booleans.yes")).toEqual(true);
|
250
|
+
expect(I18n.translate("booleans.no")).toEqual(false);
|
241
251
|
});
|
242
252
|
|
243
253
|
it("escapes $ when doing substitution (IE)", function(){
|
244
254
|
I18n.locale = "en";
|
245
255
|
|
246
|
-
expect(I18n.
|
247
|
-
expect(I18n.
|
248
|
-
expect(I18n.
|
256
|
+
expect(I18n.translate("paid", {price: "$0"})).toEqual("You were paid $0");
|
257
|
+
expect(I18n.translate("paid", {price: "$0.12"})).toEqual("You were paid $0.12");
|
258
|
+
expect(I18n.translate("paid", {price: "$1.35"})).toEqual("You were paid $1.35");
|
249
259
|
});
|
250
260
|
|
251
261
|
it("replaces all occurrences of escaped $", function(){
|
252
262
|
I18n.locale = "en";
|
253
263
|
|
254
|
-
expect(I18n.
|
264
|
+
expect(I18n.translate("paid_with_vat", {
|
255
265
|
price: "$0.12",
|
256
266
|
vat: "$0.02"}
|
257
267
|
)).toEqual("You were paid $0.12 (incl. VAT $0.02)");
|
@@ -259,20 +269,20 @@ describe("Translate", function(){
|
|
259
269
|
|
260
270
|
it("sets default scope", function(){
|
261
271
|
var options = {scope: "greetings"};
|
262
|
-
expect(I18n.
|
272
|
+
expect(I18n.translate("stranger", options)).toEqual("Hello stranger!");
|
263
273
|
});
|
264
274
|
|
265
275
|
it("accepts the scope as an array", function(){
|
266
|
-
expect(I18n.
|
276
|
+
expect(I18n.translate(["greetings", "stranger"])).toEqual("Hello stranger!");
|
267
277
|
});
|
268
278
|
|
269
279
|
it("accepts the scope as an array using a base scope", function(){
|
270
|
-
expect(I18n.
|
280
|
+
expect(I18n.translate(["stranger"], {scope: "greetings"})).toEqual("Hello stranger!");
|
271
281
|
});
|
272
282
|
|
273
283
|
it("returns an array with values interpolated", function(){
|
274
284
|
var options = {value: 314};
|
275
|
-
expect(I18n.
|
285
|
+
expect(I18n.translate("arrayWithParams", options)).toEqual([
|
276
286
|
null,
|
277
287
|
"An item with a param of " + options.value,
|
278
288
|
"Another item with a param of " + options.value,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
222
|
- !ruby/object:Gem::Version
|
223
223
|
version: '0'
|
224
224
|
requirements: []
|
225
|
-
rubygems_version: 3.
|
225
|
+
rubygems_version: 3.1.1
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: It's a small library to provide the Rails I18n translations on the Javascript.
|