i18n-js 3.0.0.rc10 → 3.0.0.rc11

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
  SHA1:
3
- metadata.gz: 0b54325d787e4471fabea3b33981f0b4ada0e660
4
- data.tar.gz: 94c1e7e0ef79bfb984f9725453c40aef5290d3e6
3
+ metadata.gz: 9a4b7236b1fa082ab83114e4015b4a4ba230c1f5
4
+ data.tar.gz: 8e55ab185ee081ea88b5452d1caedfc0f4feb44b
5
5
  SHA512:
6
- metadata.gz: 63dedf3a5d8d7f144773e922ba113d5586c1eb608f5745608a363dd3b5604acd38863a4978bd1bce091bfc6b033ad85bf59915985b790d96beafa7681d739833
7
- data.tar.gz: 30ee692d8f29ad98fc71014e119d41ae82490cddbd1a21a808cff54c97c25bf0c3abda5102555684c131a191e302eb93cd7fe98559dbc8aee2c8df9912d5fd79
6
+ metadata.gz: 0127486af42b8210f21513c91eadaf1481f639be02cb4197335619e11609d877c9ab7ce8f372818127c9dc04744e9251e2aef21a5d38ac82276b5dfb87684631
7
+ data.tar.gz: 9b3bd3240f25b722eb8e00332cbafc72b01f872c5ffb2e5f2236736ec4ff32026e5f317ef5dff20c30cafd8bd17f4b4a21a0e4577a7eba9cf95804e4e23c524a
@@ -8,6 +8,19 @@
8
8
  ### bug fixes
9
9
 
10
10
 
11
+
12
+ ## 3.0.0.rc11
13
+
14
+ ### breaking changes
15
+
16
+ ### enhancements
17
+
18
+ ### bug fixes
19
+
20
+ - [Ruby] Handle fallback locale without any translation properly ([#338](https://github.com/fnando/i18n-js/pull/338))
21
+ - [Ruby] Prevent translation entry with null value to override value in fallback locale(s), if enabled ([#334](https://github.com/fnando/i18n-js/pull/334))
22
+
23
+
11
24
  ## 3.0.0.rc10
12
25
 
13
26
  ### breaking changes
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # I18n.js
2
2
 
3
- [![Build Status](https://travis-ci.org/fnando/i18n-js.svg?branch=master)](https://travis-ci.org/fnando/i18n-js)
4
- [![Code Climate](https://codeclimate.com/github/fnando/i18n-js.png)](https://codeclimate.com/github/fnando/i18n-js)
3
+ [![Build Status](http://img.shields.io/travis/fnando/i18n-js.svg?style=flat-square)](https://travis-ci.org/fnando/i18n-js)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/fnando/i18n-js.svg?style=flat-square)](https://codeclimate.com/github/fnando/i18n-js)
5
+ [![Gitter](https://img.shields.io/badge/gitter-join%20chat-1dce73.svg?style=flat-square)](https://gitter.im/fnando/i18n-js)
5
6
 
6
7
  It's a small library to provide the Rails I18n translations on the JavaScript.
7
8
 
@@ -73,7 +74,11 @@ Then get the JS files following the instructions below.
73
74
 
74
75
  #### Export Configuration (For translations)
75
76
 
76
- Exported translation files generated by `I18n::JS::Middleware` or `rake i18n:js:export` can be customized with config file `config/i18n-js.yml` (use `rails generate i18n:js:config` to create it). You can even get more files generated to different folders and with different translations to best suit your needs. But this does not affect anything if you use Asset Pipeline.
77
+ Exported translation files generated by `I18n::JS::Middleware` or `rake i18n:js:export` can be customized with config file `config/i18n-js.yml`
78
+ (use `rails generate i18n:js:config` to create it).
79
+ You can even get more files generated to different folders and with different translations to best suit your needs.
80
+ The config file also affects developers using Asset Pipeline to require translations.
81
+ Except the option `file`, since all translations are required by adding `//= require i18n/translations`.
77
82
 
78
83
  Examples:
79
84
  ```yaml
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency "i18n", "~> 0.6"
22
22
  s.add_development_dependency "appraisal", "~> 2.0"
23
- s.add_development_dependency "activesupport", ">= 3"
23
+ s.add_development_dependency "activesupport", ">= 3.2.22"
24
24
  s.add_development_dependency "rspec", "~> 3.0"
25
- s.add_development_dependency "rake"
25
+ s.add_development_dependency "rake", "~> 10.0"
26
26
  s.add_development_dependency "gem-release", ">= 0.7"
27
27
 
28
28
  s.required_ruby_version = ">= 1.9.3"
@@ -65,7 +65,8 @@ module I18n
65
65
  I18n.available_locales.each do |locale|
66
66
  fallback_locales = FallbackLocales.new(fallbacks, locale)
67
67
  fallback_locales.each do |fallback_locale|
68
- result[locale] = Utils.deep_merge(result[fallback_locale], result[locale] || {})
68
+ # `result[fallback_locale]` could be missing
69
+ result[locale] = Utils.deep_merge(result[fallback_locale] || {}, result[locale] || {})
69
70
  end
70
71
  end
71
72
  end
@@ -2,8 +2,9 @@ module I18n
2
2
  module JS
3
3
  module Utils
4
4
  # deep_merge by Stefan Rusterholz, see <http://www.ruby-forum.com/topic/142809>.
5
- MERGER = proc do |key, v1, v2|
6
- Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2
5
+ # The last result is modified to treat `nil` as missing key
6
+ MERGER = proc do |_key, v1, v2|
7
+ Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : (v2.nil? ? v1 : v2)
7
8
  end
8
9
 
9
10
  HASH_NIL_VALUE_CLEANER_PROC = proc do |k, v|
@@ -4,7 +4,7 @@ module I18n
4
4
  MAJOR = 3
5
5
  MINOR = 0
6
6
  PATCH = 0
7
- STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.rc10"
7
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}.rc11"
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,4 @@
1
+ fallbacks: :pirate
2
+
3
+ translations:
4
+ - file: "tmp/i18n-js/%{locale}.js"
@@ -36,9 +36,11 @@ en:
36
36
  title: "Edit"
37
37
  foo: "Foo"
38
38
  fallback_test: "Success"
39
+ null_test: "fallback for null"
39
40
 
40
41
  de:
41
42
  fallback_test: "Erfolg"
43
+ null_test: ~
42
44
 
43
45
  fr:
44
46
  date:
@@ -259,28 +259,53 @@ EOS
259
259
  end
260
260
 
261
261
  context "fallbacks" do
262
- subject do
262
+ subject(:translations) do
263
263
  I18n::JS.translation_segments.first.translations
264
264
  end
265
265
 
266
266
  it "exports without fallback when disabled" do
267
267
  set_config "js_file_per_locale_without_fallbacks.yml"
268
268
  subject[:fr][:fallback_test].should eql(nil)
269
+ subject[:fr][:null_test].should eql(nil)
270
+ subject[:de][:null_test].should eql(nil)
269
271
  end
270
272
 
271
273
  it "exports with default_locale as fallback when enabled" do
272
274
  set_config "js_file_per_locale_with_fallbacks_enabled.yml"
273
275
  subject[:fr][:fallback_test].should eql("Success")
276
+ subject[:fr][:null_test].should eql("fallback for null")
277
+ subject[:de][:null_test].should eql("fallback for null")
274
278
  end
275
279
 
276
280
  it "exports with default_locale as fallback when enabled with :default_locale" do
277
281
  set_config "js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml"
278
282
  subject[:fr][:fallback_test].should eql("Success")
283
+ subject[:fr][:null_test].should eql("fallback for null")
284
+ subject[:de][:null_test].should eql("fallback for null")
279
285
  end
280
286
 
281
287
  it "exports with given locale as fallback" do
282
288
  set_config "js_file_per_locale_with_fallbacks_as_locale.yml"
283
289
  subject[:fr][:fallback_test].should eql("Erfolg")
290
+ subject[:fr][:null_test].should eql(nil)
291
+ subject[:de][:null_test].should eql(nil)
292
+ end
293
+
294
+ context "when given locale is in `I18n.available_locales` but its translation is missing" do
295
+ subject { translations[:fr][:fallback_test] }
296
+
297
+ let(:new_locale) { :pirate }
298
+ let!(:old_available_locales) { I18n.config.available_locales }
299
+ let!(:new_available_locales) { I18n.config.available_locales + [new_locale] }
300
+ before do
301
+ I18n.config.available_locales = new_available_locales
302
+ set_config "js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml"
303
+ end
304
+ after do
305
+ I18n.config.available_locales = old_available_locales
306
+ end
307
+
308
+ it {should eql(nil)}
284
309
  end
285
310
 
286
311
  context "with I18n::Fallbacks enabled" do
@@ -556,7 +581,7 @@ EOS
556
581
  it "exports with the keys sorted" do
557
582
  expect(subject).to eq(<<EOS
558
583
  I18n.translations || (I18n.translations = {});
559
- 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","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"}};
584
+ 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","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"}};
560
585
  EOS
561
586
  )
562
587
  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.0.0.rc10
4
+ version: 3.0.0.rc11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3'
47
+ version: 3.2.22
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3'
54
+ version: 3.2.22
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '10.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '10.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: gem-release
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -138,6 +138,7 @@ files:
138
138
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml
139
139
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml
140
140
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml
141
+ - spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml
141
142
  - spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml
142
143
  - spec/fixtures/js_file_per_locale_without_fallbacks.yml
143
144
  - spec/fixtures/js_file_with_namespace_and_pretty_print.yml
@@ -212,6 +213,7 @@ test_files:
212
213
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml
213
214
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml
214
215
  - spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml
216
+ - spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml
215
217
  - spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml
216
218
  - spec/fixtures/js_file_per_locale_without_fallbacks.yml
217
219
  - spec/fixtures/js_file_with_namespace_and_pretty_print.yml