i18n-js 3.0.7 → 3.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2750b5bafd7ceaefcf74278810f3cc126ab11d943b3bb44373d8d839ac2ff715
4
- data.tar.gz: 4fd313c8447e68f57fae8488680339bd46f475371646280324865b4b4d6437d6
3
+ metadata.gz: 820d6beeaa53ffbe74afc97313260ee0a77412a7ff576e906a1c4291a50970d0
4
+ data.tar.gz: e7a97db0d132db4de65bb1ae5c37b1ca47670f6ce76ea02e356d4bc8906343c5
5
5
  SHA512:
6
- metadata.gz: 8bccb10c908add935804e7b640a3b0fcb1b656e11f8e034791c5261103fc790272c179cd976a40ff225fc7a3eb5abc2a76e53ec7c0e421193d854e48b16313a8
7
- data.tar.gz: efacce778c4a6350eb7fca8887bdc7603afcaad0d50bf9471b14ad7df920f880f1533b3b5a94650908119daf6d0c81b306a14e077edde08a1507f2bbb7d79784
6
+ metadata.gz: c7657ce121aba975ba1b1d0acad226786ef867494e9fc1d1ec3d118f499f475ab27567cb121433f9af54c0080ac2b899edfdd1079de5497da7b936c18afe4bbb
7
+ data.tar.gz: 38a12230b043fb9f014bb33a056498071b1871155f77e27ed062a8678409a550db346c31a4264cc07bea6494601f1cc43643c0b47afad328f3aba05d0b2b8cbc
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.0.8] - 2018-06-06
22
+
23
+ ### Changed
24
+
25
+ - [JS] Interpolate translation array too
26
+ (PR: https://github.com/fnando/i18n-js/pull/498)
27
+
28
+
21
29
  ## [3.0.7] - 2018-05-30
22
30
 
23
31
  ### Fixed
@@ -301,7 +309,8 @@ And today is not April Fools' Day
301
309
 
302
310
 
303
311
 
304
- [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.0.7...HEAD
312
+ [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.0.8...HEAD
313
+ [3.0.8]: https://github.com/fnando/i18n-js/compare/v3.0.7...v3.0.8
305
314
  [3.0.7]: https://github.com/fnando/i18n-js/compare/v3.0.6...v3.0.7
306
315
  [3.0.6]: https://github.com/fnando/i18n-js/compare/v3.0.5...v3.0.6
307
316
  [3.0.5]: https://github.com/fnando/i18n-js/compare/v3.0.4...v3.0.5
@@ -598,6 +598,10 @@
598
598
 
599
599
  if (typeof(translation) === "string") {
600
600
  translation = this.interpolate(translation, options);
601
+ } else if (isArray(translation)) {
602
+ translation = translation.map(function(t) {
603
+ return this.interpolate(t, options);
604
+ }, this);
601
605
  } else if (isObject(translation) && isSet(options.count)) {
602
606
  translation = this.pluralize(options.count, scope, options);
603
607
  }
@@ -117,3 +117,92 @@ if (!Array.prototype.some)
117
117
  return false;
118
118
  };
119
119
  }
120
+
121
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
122
+ if (!Array.prototype.map) {
123
+
124
+ Array.prototype.map = function(callback/*, thisArg*/) {
125
+
126
+ var T, A, k;
127
+
128
+ if (this == null) {
129
+ throw new TypeError('this is null or not defined');
130
+ }
131
+
132
+ // 1. Let O be the result of calling ToObject passing the |this|
133
+ // value as the argument.
134
+ var O = Object(this);
135
+
136
+ // 2. Let lenValue be the result of calling the Get internal
137
+ // method of O with the argument "length".
138
+ // 3. Let len be ToUint32(lenValue).
139
+ var len = O.length >>> 0;
140
+
141
+ // 4. If IsCallable(callback) is false, throw a TypeError exception.
142
+ // See: http://es5.github.com/#x9.11
143
+ if (typeof callback !== 'function') {
144
+ throw new TypeError(callback + ' is not a function');
145
+ }
146
+
147
+ // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
148
+ if (arguments.length > 1) {
149
+ T = arguments[1];
150
+ }
151
+
152
+ // 6. Let A be a new array created as if by the expression new Array(len)
153
+ // where Array is the standard built-in constructor with that name and
154
+ // len is the value of len.
155
+ A = new Array(len);
156
+
157
+ // 7. Let k be 0
158
+ k = 0;
159
+
160
+ // 8. Repeat, while k < len
161
+ while (k < len) {
162
+
163
+ var kValue, mappedValue;
164
+
165
+ // a. Let Pk be ToString(k).
166
+ // This is implicit for LHS operands of the in operator
167
+ // b. Let kPresent be the result of calling the HasProperty internal
168
+ // method of O with argument Pk.
169
+ // This step can be combined with c
170
+ // c. If kPresent is true, then
171
+ if (k in O) {
172
+
173
+ // i. Let kValue be the result of calling the Get internal
174
+ // method of O with argument Pk.
175
+ kValue = O[k];
176
+
177
+ // ii. Let mappedValue be the result of calling the Call internal
178
+ // method of callback with T as the this value and argument
179
+ // list containing kValue, k, and O.
180
+ mappedValue = callback.call(T, kValue, k, O);
181
+
182
+ // iii. Call the DefineOwnProperty internal method of A with arguments
183
+ // Pk, Property Descriptor
184
+ // { Value: mappedValue,
185
+ // Writable: true,
186
+ // Enumerable: true,
187
+ // Configurable: true },
188
+ // and false.
189
+
190
+ // In browsers that support Object.defineProperty, use the following:
191
+ // Object.defineProperty(A, k, {
192
+ // value: mappedValue,
193
+ // writable: true,
194
+ // enumerable: true,
195
+ // configurable: true
196
+ // });
197
+
198
+ // For best browser support, use the following:
199
+ A[k] = mappedValue;
200
+ }
201
+ // d. Increase k by 1.
202
+ k++;
203
+ }
204
+
205
+ // 9. return A
206
+ return A;
207
+ };
208
+ }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module JS
5
- VERSION = "3.0.7"
5
+ VERSION = "3.0.8"
6
6
  end
7
7
  end
@@ -256,4 +256,13 @@ describe("Translate", function(){
256
256
  it("accepts the scope as an array using a base scope", function(){
257
257
  expect(I18n.t(["stranger"], {scope: "greetings"})).toEqual("Hello stranger!");
258
258
  });
259
+
260
+ it("returns an array with values interpolated", function(){
261
+ var options = {value: 314};
262
+ expect(I18n.t("arrayWithParams", options)).toEqual([
263
+ `An item with a param of ${options.value}`,
264
+ `Another item with a param of ${options.value}`,
265
+ `A last item with a param of ${options.value}`,
266
+ ]);
267
+ });
259
268
  });
@@ -58,6 +58,12 @@ var DEBUG = false;
58
58
  }
59
59
  }
60
60
  }
61
+
62
+ , arrayWithParams: [
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
+ ]
61
67
  };
62
68
 
63
69
  Translations["en-US"] = {
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.0.7
4
+ version: 3.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n