i18n_routing 0.3.2 → 0.3.3

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.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,11 @@
1
+ 0.3.3 (June 2, 2010)
2
+
3
+ * Fix Rails3 issue with nested single resource
4
+
5
+ 0.3.2 (June 2, 2010)
6
+
7
+ * Add automatically config/locales/*.yml in the i18n load path in order to fix Rails3 issue
8
+
1
9
  0.3.1 (May 27, 2010)
2
10
 
3
11
  * Add a small Rails3 verification
data/README.rdoc CHANGED
@@ -16,5 +16,6 @@ Furthermore, if the i18n gem is present on your system, Rails will load it and s
16
16
 
17
17
  * kwi (Guillaume Luccisano)
18
18
  * bigtiger (Jim Remsik)
19
+ * mixr (Reiner Dieterich)
19
20
 
20
21
  Copyright (c) 2010 Guillaume Luccisano - g-mai|: guillaume.luccisano, released under the MIT license
@@ -52,19 +52,27 @@ module I18nRouting
52
52
  send(type, *res) do
53
53
  # In the resource(s) block, we need to keep and restore some context :
54
54
 
55
- old_name = @scope[:i18n_real_resource_name]
56
- old = @scope[:scope_level_resource]
57
- old_i = @scope[:i18n_scope_level_resource]
55
+ if block
56
+ old_name = @scope[:i18n_real_resource_name]
57
+ old = @scope[:scope_level_resource]
58
58
 
59
- @scope[:i18n_real_resource_name] = resource.name
60
- @scope[:i18n_scope_level_resource] = old
61
- @scope[:scope_level_resource] = resource
59
+ @scope[:i18n_real_resource_name] = resource.name
60
+ @scope[:i18n_scope_level_resource] = old
61
+ @scope[:scope_level_resource] = resource
62
+
63
+ if type == :resource and @scope[:name_prefix]
64
+ # Need to fake name_prefix for singleton resource
65
+ @scope[:name_prefix].gsub!(Regexp.new("#{old.name}$"), resource.name)
66
+ end
62
67
 
63
- block.call if block
68
+ block.call if block
69
+
70
+ @scope[:scope_level_resource] = old
71
+ @scope[:i18n_real_resource_name] = old_name
72
+ end
64
73
 
65
74
  @scope[:i18n_scope_level_resource] = nil
66
- @scope[:scope_level_resource] = old
67
- @scope[:i18n_real_resource_name] = old_name
75
+
68
76
  end
69
77
  end
70
78
  end
@@ -229,7 +237,7 @@ module I18nRouting
229
237
  rfname = "#{m}_without_i18n_routing".to_sym
230
238
  mod.send :define_method, "#{m}_with_i18n_routing".to_sym do |*args, &block|
231
239
 
232
- if @localized_branch and @scope[:i18n_scope_level_resource] and @scope[:i18n_real_resource_name]
240
+ if @localized_branch and @scope[:i18n_scope_level_resource] and @scope[:i18n_real_resource_name]
233
241
  o = @scope[:scope_level_resource]
234
242
  @scope[:scope_level_resource] = @scope[:i18n_scope_level_resource]
235
243
 
@@ -23,6 +23,13 @@ describe :localized_routes do
23
23
  map.resources :authors do |m|
24
24
  m.resources :books
25
25
  end
26
+
27
+ map.resource :foo do |m|
28
+ m.resources :bars
29
+ m.resource :foofoo do |mm|
30
+ mm.resources :bars
31
+ end
32
+ end
26
33
 
27
34
  map.resources :universes do |m|
28
35
  m.resources :galaxies do |mm|
@@ -62,7 +69,14 @@ describe :localized_routes do
62
69
  resources :authors do
63
70
  resources :books
64
71
  end
65
-
72
+
73
+ resource :foo do
74
+ resources :bars
75
+ resource :foofoo do
76
+ resources :bars
77
+ end
78
+ end
79
+
66
80
  resources :universes do
67
81
  resources :galaxies do
68
82
  resources :planets do
@@ -223,6 +237,24 @@ describe :localized_routes do
223
237
 
224
238
  end
225
239
 
240
+ context "when nested inside a singleton resource" do
241
+
242
+ it "named routes should have corretly locale placed" do
243
+ nested_routes[:fr_foo_fr_bars].should be_nil
244
+ nested_routes[:foo_fr_bars].should_not be_nil
245
+ end
246
+
247
+ it "routes should be translated corretly" do
248
+ routes.send(:foo_bars_path).should == "/#{I18n.t :foo, :scope => :resource}/#{I18n.t :bars, :scope => :resources}"
249
+ end
250
+
251
+ it "routes should be translated corretly also with deep nested singleton resource" do
252
+ routes.send(:foo_foofoo_bars_path).should == "/#{I18n.t :foo, :scope => :resource}/#{I18n.t :foofoo, :scope => :resource}/#{I18n.t :bars, :scope => :resources}"
253
+ end
254
+
255
+
256
+ end
257
+
226
258
  context "when deeply nested" do
227
259
 
228
260
  it "named routes should not be nil" do
data/spec/locales/en.yml CHANGED
@@ -5,7 +5,9 @@ en:
5
5
  galaxies: 'galaxies-en'
6
6
  planets: 'planets-en'
7
7
  universes: 'universes-en'
8
+ bars: bars_en
8
9
  resource:
10
+ foo: foo_en
9
11
  contact: 'contact-us'
10
12
  named_routes_path:
11
13
  about: 'about-our-company'
data/spec/locales/fr.yml CHANGED
@@ -15,7 +15,10 @@ fr:
15
15
  planets: 'planetes'
16
16
  universes: 'univers'
17
17
  countries: 'pays'
18
+ bars: bars_fr
18
19
  resource:
20
+ foo: foo_fr
21
+ foofoo: froufrou
19
22
  contact: 'contactez-nous'
20
23
  named_routes_path:
21
24
  about: 'a-propos'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 3
9
+ version: 0.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Guillaume Luccisano