i18n-js 3.0.11 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7710293eab5e7adff0b04ffe9183dd61ab18c70e93d75a4680570e8da83deb81
4
- data.tar.gz: 8111e523870314db2f1aa49c305797ad1876523fccb9276fc8bd98c2b1a3bff5
3
+ metadata.gz: 1ddbdc40f7c45b3d6f6efd89f7e38ce602e06309280cf4b23a0c66fbbb465a6f
4
+ data.tar.gz: 820b05a44bcff8eb060d53a007b9d61342bfaf9d49a1286c69f9dfe2d6cf60dd
5
5
  SHA512:
6
- metadata.gz: a7f2f4b3b52dbd1528b5dde88292a4b44401c58d59d7a41da253961948ae9c7d2c1233bac4fba8208d5391e9ea6397ed019f1dda3034c89eab9774b9a86b8c3b
7
- data.tar.gz: 11be532db0104cec86932f67776754ba7f885c3f00f0335d130ebd8844abcb6fb30703b96e6e9a9827099548166963b642d5bee0f9f687ebd5e24c5598ce6971
6
+ metadata.gz: 2b9ff1a4f87ba0d8e69e0b2719a2a32ae605a96953a76e443052f7a622b6735aa5e5c0c1a7b3af50e98558c3ab9e1d04d7a32d67c5acd4cb328cd99f10092531
7
+ data.tar.gz: 76d742dd79d8af3e6d689487096efe318cd7e4eabd3b2c8c67157b90357ca8eeea106c820d3ef832ec802daefdb28e6a7081c14d9a66128c0bf3bb8fcdb031cd
@@ -18,6 +18,19 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ ## [3.1.0] - 2018-11-01
22
+
23
+ ### Added
24
+
25
+ - [Ruby] Add option to allow setting a different I18n backend
26
+ (PR: https://github.com/fnando/i18n-js/pull/519)
27
+
28
+ ### Fixed
29
+
30
+ - [JS] Fix missing translation when pluralizing with default scopes
31
+ (PR: https://github.com/fnando/i18n-js/pull/516)
32
+
33
+
21
34
  ## [3.0.11] - 2018-07-06
22
35
 
23
36
  ### Fixed
@@ -334,7 +347,8 @@ And today is not April Fools' Day
334
347
 
335
348
 
336
349
 
337
- [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.0.11...HEAD
350
+ [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.1.0...HEAD
351
+ [3.1.0]: https://github.com/fnando/i18n-js/compare/v3.0.11...v3.1.0
338
352
  [3.0.11]: https://github.com/fnando/i18n-js/compare/v3.0.10...v3.0.11
339
353
  [3.0.10]: https://github.com/fnando/i18n-js/compare/v3.0.9...v3.0.10
340
354
  [3.0.9]: https://github.com/fnando/i18n-js/compare/v3.0.8...v3.0.9
data/README.md CHANGED
@@ -339,7 +339,12 @@ I18n.t("some.scoped.translation", {locale: "fr"});
339
339
  You can also interpolate values:
340
340
 
341
341
  ```javascript
342
- I18n.t("hello", {name: "John Doe"});
342
+ // You need the `translations` object setup first
343
+ I18n.translations["en"] = {
344
+ greeting: "Hello %{name}"
345
+ }
346
+
347
+ I18n.t("greeting", {name: "John Doe"});
343
348
  ```
344
349
  You can set default values for missing scopes:
345
350
  ```javascript
@@ -576,14 +581,16 @@ I18n.translations["en"] = {
576
581
  I18n.l("date.formats.ordinal_day", "2009-09-18", { day: '18th' }); // Sep 18th
577
582
  ```
578
583
 
579
- If you prefer, you can use the `I18n.strftime` function to format dates.
584
+ If you prefer, you can use the `I18n.toTime` and `I18n.strftime` functions to format dates.
580
585
 
581
586
  ```javascript
582
587
  var date = new Date();
588
+ I18n.toTime("date.formats.short", "2009-09-18");
589
+ I18n.toTime("date.formats.short", date);
583
590
  I18n.strftime(date, "%d/%m/%Y");
584
591
  ```
585
592
 
586
- The accepted formats are:
593
+ The accepted formats for `I18n.strftime` are:
587
594
 
588
595
  %a - The abbreviated weekday name (Sun)
589
596
  %A - The full weekday name (Sunday)
@@ -813,6 +820,13 @@ So ensure sprockets is loaded before this gem like moving entry of sprockets in
813
820
 
814
821
  **Note:** See issue [#404](https://github.com/fnando/i18n-js/issues/404) for more details and discussion of this issue.
815
822
 
823
+ ### JS `I18n.toCurrency` & `I18n.toNumber` cannot handle large integers
824
+
825
+ The above methods use `toFixed` and it only supports 53 bit integers.
826
+ Ref: http://2ality.com/2012/07/large-integers.html
827
+
828
+ Feel free to find & discuss possible solution(s) at issue [#511](https://github.com/fnando/i18n-js/issues/511)
829
+
816
830
 
817
831
  ## Maintainer
818
832
 
@@ -575,6 +575,7 @@
575
575
  var translationOptions = this.createTranslationOptions(scope, options);
576
576
 
577
577
  var translation;
578
+ var usedScope = scope;
578
579
 
579
580
  var optionsWithoutDefault = this.prepareOptions(options)
580
581
  delete optionsWithoutDefault.defaultValue
@@ -584,7 +585,8 @@
584
585
  var translationFound =
585
586
  translationOptions.some(function(translationOption) {
586
587
  if (isSet(translationOption.scope)) {
587
- translation = this.lookup(translationOption.scope, optionsWithoutDefault);
588
+ usedScope = translationOption.scope;
589
+ translation = this.lookup(usedScope, optionsWithoutDefault);
588
590
  } else if (isSet(translationOption.message)) {
589
591
  translation = lazyEvaluate(translationOption.message, scope);
590
592
  }
@@ -605,7 +607,7 @@
605
607
  return (typeof(t) === "string" ? this.interpolate(t, options) : t);
606
608
  }, this);
607
609
  } else if (isObject(translation) && isSet(options.count)) {
608
- translation = this.pluralize(options.count, scope, options);
610
+ translation = this.pluralize(options.count, usedScope, options);
609
611
  }
610
612
 
611
613
  return translation;
@@ -28,6 +28,15 @@ module I18n
28
28
  @config_file_path = new_path
29
29
  end
30
30
 
31
+ # Allow using a different backend than the one globally configured
32
+ def self.backend
33
+ @backend ||= I18n.backend
34
+ end
35
+
36
+ def self.backend=(alternative_backend)
37
+ @backend = alternative_backend
38
+ end
39
+
31
40
  # Export translations to JavaScript, considering settings
32
41
  # from configuration file
33
42
  def self.export
@@ -161,7 +170,7 @@ module I18n
161
170
 
162
171
  # Initialize and return translations
163
172
  def self.translations
164
- ::I18n.backend.instance_eval do
173
+ self.backend.instance_eval do
165
174
  init_translations unless initialized?
166
175
  # When activesupport is absent,
167
176
  # the core extension (`#slice`) from `i18n` gem will be used instead
@@ -57,7 +57,7 @@ module I18n
57
57
  #
58
58
  # Maybe this should be fixed within I18n.
59
59
  def using_i18n_fallbacks_module?
60
- I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks)
60
+ I18n::JS.backend.class.included_modules.include?(I18n::Backend::Fallbacks)
61
61
  end
62
62
 
63
63
  def ensure_valid_fallbacks_as_array!
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module JS
5
- VERSION = "3.0.11"
5
+ VERSION = "3.1.0"
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18n-js",
3
- "version": "3.0.11",
3
+ "version": "3.1.0",
4
4
  "description": "A javascript library similar to Ruby on Rails i18n gem",
5
5
  "author": "Nando Vieira",
6
6
  "license": "MIT",
@@ -190,6 +190,13 @@ describe("Translate", function(){
190
190
  actual = I18n.t("foo", options);
191
191
  expect(actual).toEqual("FOO");
192
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
+ })
193
200
  });
194
201
 
195
202
  it("uses default value for simple translation", function(){
@@ -55,10 +55,10 @@ describe I18n::JS::FallbackLocales do
55
55
  let(:backend_with_fallbacks) { backend_class_with_fallbacks.new }
56
56
 
57
57
  before do
58
- I18n.backend = backend_with_fallbacks
58
+ I18n::JS.backend = backend_with_fallbacks
59
59
  I18n.fallbacks[:fr] = [:de, :en]
60
60
  end
61
- after { I18n.backend = I18n::Backend::Simple.new }
61
+ after { I18n::JS.backend = I18n::Backend::Simple.new }
62
62
 
63
63
  context "given true as fallbacks" do
64
64
  let(:fallbacks) { true }
@@ -313,10 +313,10 @@ EOS
313
313
  let!(:old_backebad) { I18n.backend }
314
314
 
315
315
  before do
316
- I18n.backend = backend_with_fallbacks
316
+ I18n::JS.backend = backend_with_fallbacks
317
317
  I18n.fallbacks[:fr] = [:de, :en]
318
318
  end
319
- after { I18n.backend = old_backebad }
319
+ after { I18n::JS.backend = old_backebad }
320
320
 
321
321
  it "exports with defined locale as fallback when enabled" do
322
322
  set_config "js_file_per_locale_with_fallbacks_enabled.yml"
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.11
4
+ version: 3.1.0
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-07-06 00:00:00.000000000 Z
11
+ date: 2018-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n