i18n_routing 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +8 -0
- data/README.rdoc +1 -0
- data/lib/i18n_routing_rails3.rb +18 -10
- data/spec/i18n_routing/i18n_spec.rb +33 -1
- data/spec/locales/en.yml +2 -0
- data/spec/locales/fr.yml +3 -0
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
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
|
data/lib/i18n_routing_rails3.rb
CHANGED
@@ -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
|
-
|
56
|
-
|
57
|
-
|
55
|
+
if block
|
56
|
+
old_name = @scope[:i18n_real_resource_name]
|
57
|
+
old = @scope[:scope_level_resource]
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
data/spec/locales/fr.yml
CHANGED