i18n-js 3.4.0 → 3.4.1

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: e862238199baf310221642a6913ce7d07b87b2c6934e691bed7bc19a613c09b7
4
- data.tar.gz: cdc3db450f6613e82246f2b2ba303ae706bbdaadebee84d34024cd8fb371308c
3
+ metadata.gz: 8e97276215fc1d53677d4a73d8fa078d476fbb6400047e43b42ea723eb0df22d
4
+ data.tar.gz: 496f8b37aeaceed790124ddbe359ac11831aa83b9b61a39ae1634ecff2187837
5
5
  SHA512:
6
- metadata.gz: 2bc681b8e0b8e7260fd5dfdea56c3733234c8c8afedd0e4c6492ef65356e8b7b6d5ee2e959d5ba26751860c89e237813960e5bc4a45cdb7dbd525fe396277718
7
- data.tar.gz: 7aaf234e4f39b7f3eeeff50cadd7f6f8625e235477a83d58bbcf17c30ef7e09ab086de27c85fe5c5f802b6e4f935d81a203abccae80bc65c53a6e549eeb989fb
6
+ metadata.gz: 7ee645b6b5040548d97df6dbccdbcb90f3f8093ed361c5e83abd822de102bbcf963778b60bc7c76a31f6ada69afe20c1422a420ff052f37eb816d1ef3a22155e
7
+ data.tar.gz: 395386008e73365635030bddb34a6211d0bc7914fd1822184b3a14a92097d3693ee5834a4cca85f41d584f2b7e46ec528b0fc285d63a9fd93925ee3ffe7c5ab5
data/.travis.yml CHANGED
@@ -34,5 +34,4 @@ matrix:
34
34
  allow_failures:
35
35
  - rvm: ruby-head
36
36
  notifications:
37
- webhooks: https://www.travisbuddy.com/
38
- on_success: never
37
+ webhooks: https://www.travisbuddy.com/?insertMode=update
data/CHANGELOG.md CHANGED
@@ -18,11 +18,19 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ ## [3.4.1] - 2019-11-01
22
+
23
+ ### Fixed
24
+
25
+ - [Ruby] Fix merging of plural keys to work with fallbacks that aren't overridden
26
+ (PR: https://github.com/fnando/i18n-js/pull/551)
27
+
28
+
21
29
  ## [3.4.0] - 2019-10-15
22
30
 
23
31
  ### Added
24
32
 
25
- - Allow `prefix` to be added to generated translations files
33
+ - [Ruby] Allow `prefix` to be added to generated translations files
26
34
  (PR: https://github.com/fnando/i18n-js/pull/549)
27
35
 
28
36
 
@@ -30,14 +38,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
30
38
 
31
39
  ### Added
32
40
 
33
- - Support for `%P`, `%Z`, and `%l` strftime formats to match Ruby strftime
41
+ - [JS] Support for `%P`, `%Z`, and `%l` strftime formats to match Ruby strftime
42
+ (PR: https://github.com/fnando/i18n-js/pull/537)
34
43
 
35
44
 
36
45
  ## [3.2.3] - 2019-05-24
37
46
 
38
47
  ### Changed
39
48
 
40
- - Allow rails 6 to be used with this gem
49
+ - [Ruby] Allow rails 6 to be used with this gem
41
50
  (PR: https://github.com/fnando/i18n-js/pull/536)
42
51
 
43
52
 
@@ -408,7 +417,8 @@ And today is not April Fools' Day
408
417
 
409
418
 
410
419
 
411
- [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.4.0...HEAD
420
+ [Unreleased]: https://github.com/fnando/i18n-js/compare/v3.4.1...HEAD
421
+ [3.4.1]: https://github.com/fnando/i18n-js/compare/v3.4.0...v3.4.1
412
422
  [3.4.0]: https://github.com/fnando/i18n-js/compare/v3.3.0...v3.4.0
413
423
  [3.3.0]: https://github.com/fnando/i18n-js/compare/v3.2.3...v3.3.0
414
424
  [3.2.3]: https://github.com/fnando/i18n-js/compare/v3.2.2...v3.2.3
data/README.md CHANGED
@@ -248,7 +248,7 @@ MyNamespace.translations["en"] = { ... }
248
248
  ```
249
249
 
250
250
 
251
- ### Adding a line at the beggining of the translations file (useful for imports)
251
+ ### Adding a line at the beginning of the translations file (useful for imports)
252
252
 
253
253
  Setting the `prefix: "import I18n from 'i18n-js';\n"` option will add the line at the beggining of the resultant translation file.
254
254
  This can be useful to use this gem with the [i18n-js](https://www.npmjs.com/package/i18n-js) npm package, which is quite useful to use it with webpack.
data/lib/i18n/js/utils.rb CHANGED
@@ -6,17 +6,20 @@ module I18n
6
6
  # Based on deep_merge by Stefan Rusterholz, see <http://www.ruby-forum.com/topic/142809>.
7
7
  # This method is used to handle I18n fallbacks. Given two equivalent path nodes in two locale trees:
8
8
  # 1. If the node in the current locale appears to be an I18n pluralization (:one, :other, etc.),
9
- # use the node as-is without merging. This prevents mixing locales with different pluralization schemes.
10
- # 2. Else if both nodes are Hashes, combine (merge) the key-value pairs of the two nodes into one,
9
+ # use the node, but merge in any missing/non-nil keys from the fallback (default) locale.
10
+ # 2. Else if both nodes are Hashes, combine (merge) the key-value pairs of the two nodes into one,
11
11
  # prioritizing the current locale.
12
12
  # 3. Else if either node is nil, use the other node.
13
+ PLURAL_MERGER = proc do |_key, v1, v2|
14
+ v1 || v2
15
+ end
13
16
  MERGER = proc do |_key, v1, v2|
14
17
  if Hash === v2 && (v2.keys - PLURAL_KEYS).empty?
15
- v2
18
+ slice(v2.merge(v1, &PLURAL_MERGER), v2.keys)
16
19
  elsif Hash === v1 && Hash === v2
17
20
  v1.merge(v2, &MERGER)
18
21
  else
19
- v2.nil? ? v1 : v2
22
+ v2 || v1
20
23
  end
21
24
  end
22
25
 
@@ -24,6 +27,14 @@ module I18n
24
27
  v.kind_of?(Hash) ? (v.delete_if(&HASH_NIL_VALUE_CLEANER_PROC); false) : v.nil?
25
28
  end
26
29
 
30
+ def self.slice(hash, keys)
31
+ if hash.respond_to?(:slice) # ruby 2.5 onwards
32
+ hash.slice(*keys)
33
+ else
34
+ hash.select {|key, _| keys.include?(key)}
35
+ end
36
+ end
37
+
27
38
  def self.strip_keys_with_nil_values(hash)
28
39
  hash.dup.delete_if(&HASH_NIL_VALUE_CLEANER_PROC)
29
40
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module JS
5
- VERSION = "3.4.0"
5
+ VERSION = "3.4.1"
6
6
  end
7
7
  end
@@ -40,6 +40,20 @@ en:
40
40
  merge_plurals:
41
41
  one: Apple
42
42
  other: Apples
43
+ merge_plurals_with_no_overrides:
44
+ zero: "No Apple"
45
+ one: Apple
46
+ other: Apples
47
+ merge_plurals_with_partial_overrides:
48
+ one: Cat
49
+ other: Cats
50
+
51
+ ru:
52
+ merge_plurals_with_no_overrides:
53
+ one: кот
54
+ few: кошек
55
+ many: кошка
56
+ other: кошек
43
57
 
44
58
  de:
45
59
  fallback_test: "Erfolg"
@@ -89,6 +103,17 @@ fr:
89
103
  one: Pomme
90
104
  other: Pommes
91
105
 
106
+ en-US:
107
+ merge_plurals_with_no_overrides:
108
+ zero:
109
+ one:
110
+ other:
111
+ merge_plurals_with_partial_overrides:
112
+ one: Cat
113
+ few:
114
+ many:
115
+ other:
116
+
92
117
  ja:
93
118
  admin:
94
119
  show:
@@ -0,0 +1,4 @@
1
+ translations:
2
+ - file: "tmp/i18n-js/merge_plurals_with_no_overrides.js"
3
+ only:
4
+ - "*.merge_plurals_with_no_overrides"
@@ -0,0 +1,4 @@
1
+ translations:
2
+ - file: "tmp/i18n-js/merge_plurals_with_partial_overrides.js"
3
+ only:
4
+ - "*.merge_plurals_with_partial_overrides"
@@ -598,7 +598,7 @@ EOS
598
598
  it "exports with the keys sorted" do
599
599
  expect(subject).to eq <<EOS
600
600
  I18n.translations || (I18n.translations = {});
601
- I18n.translations["en"] = I18n.extend((I18n.translations["en"] || {}), {"admin":{"edit":{"title":"Edit"},"show":{"note":"more details","title":"Show"}},"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"formats":{"default":"%Y-%m-%d","long":"%B %d, %Y","short":"%b %d"},"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"]},"fallback_test":"Success","foo":"Foo","merge_plurals":{"one":"Apple","other":"Apples"},"null_test":"fallback for null","number":{"currency":{"format":{"delimiter":",","format":"%u%n","precision":2,"separator":".","unit":"$"}},"format":{"delimiter":",","precision":3,"separator":"."}},"time":{"am":"am","formats":{"default":"%a, %d %b %Y %H:%M:%S %z","long":"%B %d, %Y %H:%M","short":"%d %b %H:%M"},"pm":"pm"}});
601
+ I18n.translations["en"] = I18n.extend((I18n.translations["en"] || {}), {"admin":{"edit":{"title":"Edit"},"show":{"note":"more details","title":"Show"}},"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"formats":{"default":"%Y-%m-%d","long":"%B %d, %Y","short":"%b %d"},"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"]},"fallback_test":"Success","foo":"Foo","merge_plurals":{"one":"Apple","other":"Apples"},"merge_plurals_with_no_overrides":{"one":"Apple","other":"Apples","zero":"No Apple"},"merge_plurals_with_partial_overrides":{"one":"Cat","other":"Cats"},"null_test":"fallback for null","number":{"currency":{"format":{"delimiter":",","format":"%u%n","precision":2,"separator":".","unit":"$"}},"format":{"delimiter":",","precision":3,"separator":"."}},"time":{"am":"am","formats":{"default":"%a, %d %b %Y %H:%M:%S %z","long":"%B %d, %Y %H:%M","short":"%d %b %H:%M"},"pm":"pm"}});
602
602
  EOS
603
603
  end
604
604
  end
@@ -658,6 +658,59 @@ EOS
658
658
  expect(subject).to eq <<EOS
659
659
  I18n.translations || (I18n.translations = {});
660
660
  I18n.translations[\"en\"] = I18n.extend((I18n.translations[\"en\"] || {}), {\"merge_plurals\":{\"one\":\"Apple\",\"other\":\"Apples\"}});\nI18n.translations[\"fr\"] = I18n.extend((I18n.translations[\"fr\"] || {}), {\"merge_plurals\":{\"one\":\"Pomme\",\"other\":\"Pommes\",\"zero\":\"Pomme\"}});
661
+ EOS
662
+ end
663
+ end
664
+
665
+ describe "merging plural keys, with fallbacks" do
666
+ before do
667
+ stub_const('I18n::JS::DEFAULT_EXPORT_DIR_PATH', temp_path)
668
+ end
669
+
670
+ subject do
671
+ File.read(File.join(I18n::JS.export_i18n_js_dir_path, "merge_plurals_with_no_overrides.js"))
672
+ end
673
+
674
+ it "should correctly merge the plural keys" do
675
+ set_config "merge_plurals_with_no_overrides.yml"
676
+ I18n::JS.export
677
+ file_should_exist "merge_plurals_with_no_overrides.js"
678
+
679
+ expect(subject).to eq <<EOS
680
+ I18n.translations || (I18n.translations = {});
681
+ I18n.translations[\"de\"] = I18n.extend((I18n.translations[\"de\"] || {}), {\"merge_plurals_with_no_overrides\":{\"one\":\"Apple\",\"other\":\"Apples\",\"zero\":\"No Apple\"}});
682
+ I18n.translations[\"en\"] = I18n.extend((I18n.translations[\"en\"] || {}), {\"merge_plurals_with_no_overrides\":{\"one\":\"Apple\",\"other\":\"Apples\",\"zero\":\"No Apple\"}});
683
+ I18n.translations[\"en-US\"] = I18n.extend((I18n.translations[\"en-US\"] || {}), {\"merge_plurals_with_no_overrides\":{\"one\":\"Apple\",\"other\":\"Apples\",\"zero\":\"No Apple\"}});
684
+ I18n.translations[\"fr\"] = I18n.extend((I18n.translations[\"fr\"] || {}), {\"merge_plurals_with_no_overrides\":{\"one\":\"Apple\",\"other\":\"Apples\",\"zero\":\"No Apple\"}});
685
+ I18n.translations[\"ja\"] = I18n.extend((I18n.translations[\"ja\"] || {}), {\"merge_plurals_with_no_overrides\":{\"one\":\"Apple\",\"other\":\"Apples\",\"zero\":\"No Apple\"}});
686
+ I18n.translations[\"ru\"] = I18n.extend((I18n.translations[\"ru\"] || {}), {\"merge_plurals_with_no_overrides\":{\"few\":\"кошек\",\"many\":\"кошка\",\"one\":\"кот\",\"other\":\"кошек\"}});
687
+ EOS
688
+ end
689
+ end
690
+
691
+ # see discussion @ https://github.com/fnando/i18n-js/pull/551#issuecomment-543205767
692
+ describe "merging plural keys, with fallbacks, with partial overrides" do
693
+ before do
694
+ stub_const('I18n::JS::DEFAULT_EXPORT_DIR_PATH', temp_path)
695
+ end
696
+
697
+ subject do
698
+ File.read(File.join(I18n::JS.export_i18n_js_dir_path, "merge_plurals_with_partial_overrides.js"))
699
+ end
700
+
701
+ it "should correctly merge the plural keys" do
702
+ set_config "merge_plurals_with_partial_overrides.yml"
703
+ I18n::JS.export
704
+ file_should_exist "merge_plurals_with_partial_overrides.js"
705
+
706
+ expect(subject).to eq <<EOS
707
+ I18n.translations || (I18n.translations = {});
708
+ I18n.translations[\"de\"] = I18n.extend((I18n.translations[\"de\"] || {}), {\"merge_plurals_with_partial_overrides\":{\"one\":\"Cat\",\"other\":\"Cats\"}});
709
+ I18n.translations[\"en\"] = I18n.extend((I18n.translations[\"en\"] || {}), {\"merge_plurals_with_partial_overrides\":{\"one\":\"Cat\",\"other\":\"Cats\"}});
710
+ I18n.translations[\"en-US\"] = I18n.extend((I18n.translations[\"en-US\"] || {}), {\"merge_plurals_with_partial_overrides\":{\"few\":null,\"many\":null,\"one\":\"Cat\",\"other\":\"Cats\"}});
711
+ I18n.translations[\"fr\"] = I18n.extend((I18n.translations[\"fr\"] || {}), {\"merge_plurals_with_partial_overrides\":{\"one\":\"Cat\",\"other\":\"Cats\"}});
712
+ I18n.translations[\"ja\"] = I18n.extend((I18n.translations[\"ja\"] || {}), {\"merge_plurals_with_partial_overrides\":{\"one\":\"Cat\",\"other\":\"Cats\"}});
713
+ I18n.translations[\"ru\"] = I18n.extend((I18n.translations[\"ru\"] || {}), {\"merge_plurals_with_partial_overrides\":{\"one\":\"Cat\",\"other\":\"Cats\"}});
661
714
  EOS
662
715
  end
663
716
  end
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.4.0
4
+ version: 3.4.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-10-15 00:00:00.000000000 Z
11
+ date: 2019-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -165,6 +165,8 @@ files:
165
165
  - spec/fixtures/json_only.yml
166
166
  - spec/fixtures/locales.yml
167
167
  - spec/fixtures/merge_plurals.yml
168
+ - spec/fixtures/merge_plurals_with_no_overrides.yml
169
+ - spec/fixtures/merge_plurals_with_partial_overrides.yml
168
170
  - spec/fixtures/multiple_conditions.yml
169
171
  - spec/fixtures/multiple_conditions_per_locale.yml
170
172
  - spec/fixtures/multiple_files.yml
@@ -245,6 +247,8 @@ test_files:
245
247
  - spec/fixtures/json_only.yml
246
248
  - spec/fixtures/locales.yml
247
249
  - spec/fixtures/merge_plurals.yml
250
+ - spec/fixtures/merge_plurals_with_no_overrides.yml
251
+ - spec/fixtures/merge_plurals_with_partial_overrides.yml
248
252
  - spec/fixtures/multiple_conditions.yml
249
253
  - spec/fixtures/multiple_conditions_per_locale.yml
250
254
  - spec/fixtures/multiple_files.yml