i18n_routing 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/MIT-LICENSE +0 -0
- data/README.rdoc +1 -6
- data/Rakefile +0 -0
- data/init.rb +0 -0
- data/lib/i18n_routing.rb +2 -0
- data/lib/i18n_routing_common.rb +46 -0
- data/lib/i18n_routing_rails2.rb +6 -7
- data/lib/i18n_routing_rails3.rb +133 -22
- data/spec/i18n_routing/i18n_spec.rb +105 -47
- data/spec/locales/en.yml +0 -0
- data/spec/locales/fr.yml +12 -1
- data/spec/spec_helper.rb +0 -0
- metadata +6 -7
- data/i18n_routing.gemspec +0 -17
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.3.0 (May 27, 2010)
|
2
|
+
|
3
|
+
* Add support for translating path_names, member and collection
|
4
|
+
* Fix Rails3 nested resources
|
5
|
+
* All specs are now passing under both Rails 2.3.5 and Rails 3
|
6
|
+
|
1
7
|
0.2.4 (Apr 21, 2010)
|
2
8
|
|
3
9
|
* Fix latest Rails3 edge compatibility (previous rails3 beta version not supported any more)
|
data/MIT-LICENSE
CHANGED
File without changes
|
data/README.rdoc
CHANGED
@@ -4,12 +4,7 @@ I18n_routing is a plugin for Ruby on Rails that lets you easily translate your r
|
|
4
4
|
|
5
5
|
All necessary informations are available on the wiki : http://wiki.github.com/kwi/i18n_routing
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
== TODO
|
10
|
-
|
11
|
-
* Do nested resources for Rails3
|
12
|
-
* Another bug fix ?
|
7
|
+
Works with Rails 2.3 and Rails3 !
|
13
8
|
|
14
9
|
== Contributors
|
15
10
|
|
data/Rakefile
CHANGED
File without changes
|
data/init.rb
CHANGED
File without changes
|
data/lib/i18n_routing.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# I18nRouting module for common usage methods
|
4
|
+
module I18nRouting
|
5
|
+
# Return the correct translation for given values
|
6
|
+
def self.translation_for(name, type = :resources, option = nil)
|
7
|
+
|
8
|
+
# First, if an option is given, try to get the translation in the routes scope
|
9
|
+
if option
|
10
|
+
t = I18n.t(option.to_sym, :scope => "routes.#{name}.#{type}".to_sym, :default => option.to_s)
|
11
|
+
|
12
|
+
return (t || name)
|
13
|
+
else
|
14
|
+
# Try to get the translation in routes namescope first
|
15
|
+
t = I18n.t(:as, :scope => "routes.#{name}".to_sym, :default => name.to_s)
|
16
|
+
return t if t and t != name.to_s
|
17
|
+
|
18
|
+
I18n.t(name.to_s, :scope => type, :default => name.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
DefaultPathNames = [:new, :edit]
|
23
|
+
PathNamesKeys = [:path_names, :member, :collection]
|
24
|
+
|
25
|
+
# Return path names hash for given resource
|
26
|
+
def self.path_names(name, options)
|
27
|
+
h = (options[:path_names] || {}).dup
|
28
|
+
|
29
|
+
path_names = DefaultPathNames
|
30
|
+
PathNamesKeys.each do |v|
|
31
|
+
path_names += options[v].keys if options[v] and Hash === options[v]
|
32
|
+
end
|
33
|
+
|
34
|
+
path_names.each do |pn|
|
35
|
+
n = translation_for(name, :path_names, pn)
|
36
|
+
n = nil if n == pn.to_s
|
37
|
+
# Get default path_names in path_names scope if no path_names found
|
38
|
+
n ||= I18n.t(pn, :scope => :path_names, :default => name.to_s)
|
39
|
+
|
40
|
+
h[pn] = n if n and n != name.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
return h
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/i18n_routing_rails2.rb
CHANGED
@@ -93,13 +93,13 @@ module ActionController
|
|
93
93
|
alias_method :gl_add_named_route, :add_named_route
|
94
94
|
def add_named_route(name, path, options = {}) #:nodoc:
|
95
95
|
if @locales and !path.blank? and !Thread.current[:i18n_no_named_localization]
|
96
|
-
#
|
96
|
+
# Here, try to translate standard named routes
|
97
97
|
name = name.to_s
|
98
98
|
|
99
99
|
@locales.each do |l|
|
100
100
|
I18n.locale = l
|
101
101
|
nt = "#{l}_#{name}"
|
102
|
-
if nt != name and ((t =
|
102
|
+
if nt != name and ((t = I18nRouting.translation_for(path, :named_routes_path)) != path)
|
103
103
|
gl_add_named_route(nt, t, options.merge(:glang => l))
|
104
104
|
puts("[I18n] > localize %-10s: %40s (%s) => %s" % ['route', name, l, t]) if @i18n_verbose
|
105
105
|
end
|
@@ -164,21 +164,20 @@ module ActionController
|
|
164
164
|
options = entities.extract_options!
|
165
165
|
opts = options.dup
|
166
166
|
|
167
|
-
opts[:controller] ||= name
|
168
|
-
|
169
167
|
locales = @set.locales
|
170
|
-
translated = nil
|
171
168
|
localized(nil) do
|
172
169
|
locales.each do |l|
|
173
170
|
I18n.locale = l
|
174
171
|
nt = "#{l}_#{name}"
|
175
|
-
if nt != name and ((t =
|
172
|
+
if nt != name and ((t = I18nRouting.translation_for(name, namespace)) != name)
|
176
173
|
nt = "#{l}_#{name}"
|
177
174
|
opts[:as] = t
|
178
175
|
opts[:glang] = l
|
176
|
+
opts[:controller] ||= name
|
179
177
|
opts[:real_path] = opts[:singular] || name
|
178
|
+
opts[:path_names] = I18nRouting.path_names(name, options)
|
179
|
+
|
180
180
|
localized([l]) do
|
181
|
-
translated = true
|
182
181
|
switch_no_named_localization(true) do
|
183
182
|
send(type, nt.to_sym, opts, &block)
|
184
183
|
end
|
data/lib/i18n_routing_rails3.rb
CHANGED
@@ -7,6 +7,17 @@ module I18nRouting
|
|
7
7
|
module Mapper
|
8
8
|
|
9
9
|
private
|
10
|
+
|
11
|
+
# Just create a Mapper:Resource with given parameters
|
12
|
+
def resource_from_params(type, *resources)
|
13
|
+
res = resources.clone
|
14
|
+
|
15
|
+
options = res.extract_options!
|
16
|
+
r = res.first
|
17
|
+
|
18
|
+
type == :resource ? ActionDispatch::Routing::Mapper::SingletonResource.new(r, options.dup) : ActionDispatch::Routing::Mapper::Resource.new(r, options.dup)
|
19
|
+
end
|
20
|
+
|
10
21
|
# Localize a resources or a resource
|
11
22
|
def localized_resources(type = :resources, *resources, &block)
|
12
23
|
localizable_route = nil
|
@@ -16,12 +27,13 @@ module I18nRouting
|
|
16
27
|
|
17
28
|
options = res.extract_options!
|
18
29
|
r = res.first
|
30
|
+
|
19
31
|
resource = type == :resource ? ActionDispatch::Routing::Mapper::SingletonResource.new(r, options.dup) : ActionDispatch::Routing::Mapper::Resource.new(r, options.dup)
|
20
32
|
|
21
33
|
# Check for translated resource
|
22
34
|
@locales.each do |locale|
|
23
35
|
I18n.locale = locale
|
24
|
-
localized_path =
|
36
|
+
localized_path = I18nRouting.translation_for(resource.name, type)
|
25
37
|
|
26
38
|
# A translated route exists :
|
27
39
|
if localized_path and localized_path != resource.name.to_s
|
@@ -29,14 +41,31 @@ module I18nRouting
|
|
29
41
|
opts = options.dup
|
30
42
|
opts[:path] = localized_path.to_sym
|
31
43
|
opts[:controller] ||= r
|
32
|
-
|
33
|
-
opts[:constraints][:i18n_locale] = locale.to_s
|
44
|
+
|
34
45
|
res = ["#{locale}_#{r}".to_sym, opts]
|
35
46
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
47
|
+
constraints = opts[:constraints] ? opts[:constraints].dup : {}
|
48
|
+
constraints[:i18n_locale] = locale.to_s
|
49
|
+
|
50
|
+
scope(:constraints => constraints, :path_names => I18nRouting.path_names(resource.name, @scope)) do
|
51
|
+
localized_branch(locale) do
|
52
|
+
send(type, *res) do
|
53
|
+
# In the resource(s) block, we need to keep and restore some context :
|
54
|
+
|
55
|
+
old_name = @scope[:i18n_real_resource_name]
|
56
|
+
old = @scope[:scope_level_resource]
|
57
|
+
old_i = @scope[:i18n_scope_level_resource]
|
58
|
+
|
59
|
+
@scope[:i18n_real_resource_name] = resource.name
|
60
|
+
@scope[:i18n_scope_level_resource] = old
|
61
|
+
@scope[:scope_level_resource] = resource
|
62
|
+
|
63
|
+
block.call if block
|
64
|
+
|
65
|
+
@scope[:i18n_scope_level_resource] = nil
|
66
|
+
@scope[:scope_level_resource] = old
|
67
|
+
@scope[:i18n_real_resource_name] = old_name
|
68
|
+
end
|
40
69
|
end
|
41
70
|
end
|
42
71
|
|
@@ -47,11 +76,11 @@ module I18nRouting
|
|
47
76
|
return localizable_route
|
48
77
|
end
|
49
78
|
|
50
|
-
# Set if the next route
|
79
|
+
# Set if the next route created will be a localized route or not
|
51
80
|
# If yes, localizable is a name, or a Mapper::Resource
|
52
81
|
# Can take a block, if so, save the current context, set the new
|
53
82
|
# Call the block, then restore the old context and return the block return
|
54
|
-
def set_localizable_route(localizable)
|
83
|
+
def set_localizable_route(localizable)
|
55
84
|
if block_given?
|
56
85
|
old = @set.named_routes.localizable
|
57
86
|
@set.named_routes.set_localizable_route(localizable)
|
@@ -62,6 +91,15 @@ module I18nRouting
|
|
62
91
|
@set.named_routes.set_localizable_route(localizable)
|
63
92
|
end
|
64
93
|
end
|
94
|
+
|
95
|
+
def localizable_route
|
96
|
+
@set.named_routes.localizable
|
97
|
+
end
|
98
|
+
|
99
|
+
# Return the aproximate deep in scope level
|
100
|
+
def nested_deep
|
101
|
+
(@scope and Array === @scope[:blocks] and @scope[:scope_level]) ? @scope[:blocks].size : 0
|
102
|
+
end
|
65
103
|
|
66
104
|
public
|
67
105
|
|
@@ -100,15 +138,35 @@ module I18nRouting
|
|
100
138
|
def localized(locales = I18n.available_locales, opts = {})
|
101
139
|
old_value = @locales
|
102
140
|
@locales = locales
|
103
|
-
@i18n_verbose
|
141
|
+
@i18n_verbose ||= opts.delete(:verbose)
|
104
142
|
yield
|
105
143
|
ensure
|
106
144
|
@locales = old_value
|
107
145
|
end
|
108
|
-
|
146
|
+
|
147
|
+
# Create a branch for create routes in the specified locale
|
148
|
+
def localized_branch(locale)
|
149
|
+
set_localizable_route(nil) do
|
150
|
+
old = @localized_branch
|
151
|
+
@localized_branch = locale
|
152
|
+
localized([locale]) do
|
153
|
+
yield
|
154
|
+
end
|
155
|
+
@localized_branch = old
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Set we do not want to localize next resource
|
160
|
+
def skip_localization
|
161
|
+
old = @skip_localization
|
162
|
+
@skip_localization = @localized_branch ? nil : true
|
163
|
+
yield
|
164
|
+
@skip_localization = old
|
165
|
+
end
|
166
|
+
|
109
167
|
def match(*args)
|
110
168
|
# Localize simple match only if there is no resource scope.
|
111
|
-
if args.size == 1 and @locales and
|
169
|
+
if args.size == 1 and @locales and !parent_resource and args.first[:as]
|
112
170
|
@locales.each do |locale|
|
113
171
|
mapping = LocalizedMapping.new(locale, @set, @scope, Marshal.load(Marshal.dump(args))) # Dump is dirty but how to make deep cloning easily ? :/
|
114
172
|
if mapping.localizable?
|
@@ -125,20 +183,73 @@ module I18nRouting
|
|
125
183
|
|
126
184
|
super
|
127
185
|
end
|
186
|
+
|
187
|
+
def create_globalized_resources(type, *resources, &block)
|
128
188
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
189
|
+
#puts "#{' ' * nested_deep}Call #{type} : #{resources.inspect} (#{@locales.inspect}) (#{@localized_branch}) (#{@skip_localization})"
|
190
|
+
|
191
|
+
cur_scope = nil
|
192
|
+
if @locales
|
193
|
+
localized = localized_resources(type, *resources, &block) if !@skip_localization
|
194
|
+
|
195
|
+
## We do not translate if we are in a translations branch :
|
196
|
+
return if localized and nested_deep > 0
|
197
|
+
|
198
|
+
# Set the current standard resource in order to customize url helper :
|
199
|
+
if !@localized_branch
|
200
|
+
r = resource_from_params(type, *resources)
|
201
|
+
cur_scope = (parent_resource and parent_resource.name == r.name) ? parent_resource : r
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
set_localizable_route(cur_scope) do
|
206
|
+
skip_localization do
|
207
|
+
#puts "#{' ' * nested_deep} \\- Call original #{type} : for #{resources.inspect}}"
|
208
|
+
send("#{type}_without_i18n_routing".to_sym, *resources, &block)
|
209
|
+
end
|
133
210
|
end
|
211
|
+
|
134
212
|
end
|
213
|
+
|
214
|
+
# Alias methods in order to handle i18n routes
|
215
|
+
def self.included(mod)
|
216
|
+
mod.send :alias_method_chain, :resource, :i18n_routing
|
217
|
+
mod.send :alias_method_chain, :resources, :i18n_routing
|
218
|
+
|
219
|
+
# Here we redefine some methods, in order to handle
|
220
|
+
# correct path_names translation on the fly
|
221
|
+
[:map_method, :member, :collection].each do |m|
|
222
|
+
rfname = "#{m}_without_i18n_routing".to_sym
|
223
|
+
mod.send :define_method, "#{m}_with_i18n_routing".to_sym do |*args, &block|
|
224
|
+
|
225
|
+
if @localized_branch and @scope[:i18n_scope_level_resource] and @scope[:i18n_real_resource_name]
|
226
|
+
o = @scope[:scope_level_resource]
|
227
|
+
@scope[:scope_level_resource] = @scope[:i18n_scope_level_resource]
|
228
|
+
|
229
|
+
pname = @scope[:path_names] || {}
|
230
|
+
pname[args[1]] = args[1]
|
231
|
+
scope(:path_names => I18nRouting.path_names(@scope[:i18n_real_resource_name], {:path_names => pname})) do
|
232
|
+
send(rfname, *args, &block)
|
233
|
+
end
|
234
|
+
@scope[:scope_level_resource] = o
|
235
|
+
return
|
236
|
+
end
|
135
237
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
238
|
+
send(rfname, *args, &block)
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
mod.send :alias_method_chain, m, :i18n_routing
|
140
243
|
end
|
141
244
|
end
|
245
|
+
|
246
|
+
def resource_with_i18n_routing(*resources, &block)
|
247
|
+
create_globalized_resources(:resource, *resources, &block)
|
248
|
+
end
|
249
|
+
|
250
|
+
def resources_with_i18n_routing(*resources, &block)
|
251
|
+
create_globalized_resources(:resources, *resources, &block)
|
252
|
+
end
|
142
253
|
|
143
254
|
end
|
144
255
|
|
@@ -153,7 +264,7 @@ module I18nRouting
|
|
153
264
|
# try to get translated path :
|
154
265
|
I18n.locale = locale
|
155
266
|
ts = @path.gsub(/^\//, '')
|
156
|
-
@localized_path = '/' +
|
267
|
+
@localized_path = '/' + I18nRouting.translation_for(ts, :named_routes_path)
|
157
268
|
|
158
269
|
# If a translated path exists, set localized infos
|
159
270
|
if @localized_path and @localized_path != @path
|
@@ -222,7 +333,7 @@ module I18nRouting
|
|
222
333
|
# Exists in order to use apropriate localized route when using url_for
|
223
334
|
module RackMountRoute
|
224
335
|
|
225
|
-
# Alias
|
336
|
+
# Alias methods in order to handle i18n routes
|
226
337
|
def self.included(mod)
|
227
338
|
mod.send :alias_method_chain, :generate, :i18n_routing
|
228
339
|
mod.send :alias_method_chain, :initialize, :i18n_routing
|
@@ -1,77 +1,94 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe :localized_routes do
|
4
|
+
|
5
|
+
@@r = nil # Global routes in order to speed up testing
|
6
|
+
|
4
7
|
before(:all) do
|
5
8
|
|
6
|
-
if
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
if !@@r
|
10
|
+
if !rails3?
|
11
|
+
ActionController::Routing::Routes.clear!
|
12
|
+
ActionController::Routing::Routes.draw do |map|
|
13
|
+
map.not_about 'not_about', :controller => 'not_about'
|
14
|
+
map.resources :not_users
|
15
|
+
map.resource :not_contact
|
12
16
|
|
13
|
-
|
14
|
-
|
17
|
+
map.localized(I18n.available_locales, :verbose => false) do
|
18
|
+
map.about 'about', :controller => 'about', :action => :show
|
15
19
|
|
16
|
-
|
17
|
-
|
20
|
+
map.resources :users, :member => {:level => :get}, :collection => {:groups => :get}
|
21
|
+
map.resource :contact
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
map.resources :authors do |m|
|
24
|
+
m.resources :books
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
map.resources :universes do |m|
|
28
|
+
m.resources :galaxies do |mm|
|
29
|
+
mm.resources :planets do |mmm|
|
30
|
+
mmm.resources :countries
|
31
|
+
end
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
29
|
-
end
|
30
36
|
|
31
|
-
|
37
|
+
@@r = ActionController::Routing::Routes
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
39
|
+
class UrlTester
|
40
|
+
include ActionController::UrlWriter
|
41
|
+
end
|
36
42
|
|
37
|
-
|
38
|
-
@r = ActionDispatch::Routing::RouteSet.new
|
39
|
-
@r.draw do
|
40
|
-
match 'not_about' => "not_about#show", :as => :not_about
|
41
|
-
resources :not_users
|
42
|
-
resource :not_contact
|
43
|
+
else
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
@@r = ActionDispatch::Routing::RouteSet.new
|
46
|
+
@@r.draw do
|
47
|
+
match 'not_about' => "not_about#show", :as => :not_about
|
48
|
+
resources :not_users
|
49
|
+
resource :not_contact
|
46
50
|
|
47
|
-
|
48
|
-
|
51
|
+
localized(I18n.available_locales, :verbose => false) do
|
52
|
+
match 'about' => "about#show", :as => :about
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
|
54
|
+
resources :users do
|
55
|
+
member do
|
56
|
+
get :level
|
57
|
+
end
|
58
|
+
get :groups, :on => :collection
|
59
|
+
end
|
60
|
+
resource :contact
|
53
61
|
|
54
|
-
|
55
|
-
|
56
|
-
|
62
|
+
resources :authors do
|
63
|
+
resources :books
|
64
|
+
end
|
65
|
+
|
66
|
+
resources :universes do
|
67
|
+
resources :galaxies do
|
68
|
+
resources :planets do
|
69
|
+
scope do
|
70
|
+
resources :countries
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
57
74
|
end
|
58
|
-
end
|
59
75
|
|
76
|
+
end
|
60
77
|
end
|
61
|
-
end
|
62
78
|
|
63
|
-
|
64
|
-
|
79
|
+
class UrlTester; end
|
80
|
+
UrlTester.send :include, @@r.url_helpers
|
65
81
|
|
82
|
+
end
|
66
83
|
end
|
67
84
|
|
68
85
|
end
|
69
86
|
|
70
|
-
let(:nested_routes) {
|
87
|
+
let(:nested_routes) { @@r.named_routes.instance_eval { routes } }
|
71
88
|
let(:routes) { UrlTester.new }
|
72
89
|
|
73
90
|
def url_for(opts)
|
74
|
-
|
91
|
+
@@r.generate_extras(opts).first
|
75
92
|
end
|
76
93
|
|
77
94
|
context "do not break existing behavior" do
|
@@ -139,11 +156,11 @@ describe :localized_routes do
|
|
139
156
|
end
|
140
157
|
|
141
158
|
it "resources generates routes using localized values" do
|
142
|
-
routes.send(:users_path).should == "/#{I18n.t :
|
159
|
+
routes.send(:users_path).should == "/#{I18n.t :as, :scope => :'routes.users'}"
|
143
160
|
end
|
144
161
|
|
145
162
|
it "url_for generates routes using localized values" do
|
146
|
-
url_for(:controller => :users).should == "/#{I18n.t :
|
163
|
+
url_for(:controller => :users).should == "/#{I18n.t :as, :scope => :'routes.users'}"
|
147
164
|
url_for(:controller => :about, :action => :show).should == "/#{I18n.t :about, :scope => :named_routes_path}"
|
148
165
|
end
|
149
166
|
|
@@ -155,6 +172,39 @@ describe :localized_routes do
|
|
155
172
|
routes.send(:universes_path).should == "/#{I18n.t :universes, :scope => :resources}"
|
156
173
|
routes.send(:universe_galaxies_path, 1).should == "/#{I18n.t :universes, :scope => :resources}/1/#{I18n.t :galaxies, :scope => :resources}"
|
157
174
|
routes.send(:universe_galaxy_planets_path, 1, 1).should == "/#{I18n.t :universes, :scope => :resources}/1/#{I18n.t :galaxies, :scope => :resources}/1/#{I18n.t :planets, :scope => :resources}"
|
175
|
+
routes.send(:universe_galaxy_planet_countries_path, 1, 1, 42).should == "/#{I18n.t :universes, :scope => :resources}/1/#{I18n.t :galaxies, :scope => :resources}/1/#{I18n.t :planets, :scope => :resources}/42/#{I18n.t :countries, :scope => :resources}"
|
176
|
+
end
|
177
|
+
|
178
|
+
context "with path_names" do
|
179
|
+
|
180
|
+
it "default translated path names" do
|
181
|
+
routes.send(:new_universe_path).should == "/#{I18n.t :universes, :scope => :resources}/#{I18n.t :new, :scope => :path_names}"
|
182
|
+
routes.send(:edit_universe_path, 42).should == "/#{I18n.t :universes, :scope => :resources}/42/#{I18n.t :edit, :scope => :path_names}"
|
183
|
+
end
|
184
|
+
|
185
|
+
it "custom translated path names" do
|
186
|
+
routes.send(:new_user_path).should == "/#{I18n.t :users, :scope => :resources}/#{I18n.t :new, :scope => :'routes.users.path_names'}"
|
187
|
+
routes.send(:edit_user_path, 42).should == "/#{I18n.t :users, :scope => :resources}/42/#{I18n.t :edit, :scope => :'routes.users.path_names'}"
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
context "with member and collection" do
|
193
|
+
|
194
|
+
it "custom member" do
|
195
|
+
I18n.locale = :en
|
196
|
+
routes.send(:level_user_path, 42).should == "/#{I18n.t :users, :scope => :resources}/42/level"
|
197
|
+
I18n.locale = :fr
|
198
|
+
routes.send(:level_user_path, 42).should == "/#{I18n.t :users, :scope => :resources}/42/#{I18n.t :level, :scope => :'routes.users.path_names'}"
|
199
|
+
end
|
200
|
+
|
201
|
+
it "custom collection" do
|
202
|
+
I18n.locale = :en
|
203
|
+
routes.send(:groups_users_path).should == "/#{I18n.t :users, :scope => :resources}/groups"
|
204
|
+
I18n.locale = :fr
|
205
|
+
routes.send(:groups_users_path).should == "/#{I18n.t :users, :scope => :resources}/#{I18n.t :groups, :scope => :'routes.users.path_names'}"
|
206
|
+
end
|
207
|
+
|
158
208
|
end
|
159
209
|
|
160
210
|
context "when nested" do
|
@@ -191,9 +241,17 @@ describe :localized_routes do
|
|
191
241
|
end
|
192
242
|
|
193
243
|
it "nested resources do not deep translate with multi helpers" do
|
194
|
-
nested_routes.keys.should_not include(:fr_author_books) #
|
195
|
-
end
|
244
|
+
nested_routes.keys.should_not include(:fr_author_books) # Do not want fr_author_books
|
245
|
+
end
|
196
246
|
|
197
247
|
end
|
198
248
|
|
249
|
+
# context "just output" do
|
250
|
+
# it "output all routes properly" do
|
251
|
+
# nested_routes.keys.collect(&:to_s).sort.each do |k|
|
252
|
+
# puts("%50s: %.80s" % [k, (nested_routes[k.to_sym].path rescue nested_routes[k.to_sym].to_s)])
|
253
|
+
# end
|
254
|
+
# end
|
255
|
+
# end
|
256
|
+
|
199
257
|
end
|
data/spec/locales/en.yml
CHANGED
File without changes
|
data/spec/locales/fr.yml
CHANGED
@@ -1,4 +1,12 @@
|
|
1
1
|
fr:
|
2
|
+
routes:
|
3
|
+
users:
|
4
|
+
as: utilisateurs
|
5
|
+
path_names:
|
6
|
+
level: 'niveau'
|
7
|
+
groups: 'groupe'
|
8
|
+
new: 'nouvel_utilisateur'
|
9
|
+
edit: 'edition_utilisateur'
|
2
10
|
resources:
|
3
11
|
users: utilisateurs
|
4
12
|
authors: 'auteurs'
|
@@ -6,8 +14,11 @@ fr:
|
|
6
14
|
galaxies: 'galaxies-en-francais'
|
7
15
|
planets: 'planetes'
|
8
16
|
universes: 'univers'
|
17
|
+
countries: 'pays'
|
9
18
|
resource:
|
10
19
|
contact: 'contactez-nous'
|
11
20
|
named_routes_path:
|
12
21
|
about: 'a-propos'
|
13
|
-
|
22
|
+
path_names:
|
23
|
+
new: 'nouveau'
|
24
|
+
edit: 'edition'
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Guillaume Luccisano
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-27 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,7 @@ extra_rdoc_files: []
|
|
41
41
|
|
42
42
|
files:
|
43
43
|
- lib/i18n_routing.rb
|
44
|
+
- lib/i18n_routing_common.rb
|
44
45
|
- lib/i18n_routing_rails2.rb
|
45
46
|
- lib/i18n_routing_rails3.rb
|
46
47
|
- spec/i18n_routing/i18n_spec.rb
|
@@ -48,12 +49,10 @@ files:
|
|
48
49
|
- spec/locales/fr.yml
|
49
50
|
- spec/spec_helper.rb
|
50
51
|
- CHANGELOG.rdoc
|
51
|
-
- i18n_routing-0.2.4.gem
|
52
|
-
- i18n_routing.gemspec
|
53
|
-
- init.rb
|
54
52
|
- MIT-LICENSE
|
55
53
|
- Rakefile
|
56
54
|
- README.rdoc
|
55
|
+
- init.rb
|
57
56
|
has_rdoc: true
|
58
57
|
homepage: http://github.com/kwi/i18n_routing
|
59
58
|
licenses: []
|
data/i18n_routing.gemspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = "i18n_routing"
|
3
|
-
s.version = "0.2.4"
|
4
|
-
s.author = "Guillaume Luccisano"
|
5
|
-
s.email = "guillaume.luccisano@gmail.com"
|
6
|
-
s.homepage = "http://github.com/kwi/i18n_routing"
|
7
|
-
s.summary = "I18n routing module for Rails 2.3.x and Rails 3. Translate your routes with ease !"
|
8
|
-
s.description = "I18n_routing is a plugin for Ruby on Rails that lets you easily translate your routes trough the I18n api included in Rails since version 2.2"
|
9
|
-
|
10
|
-
s.add_dependency('i18n', '> 0.3.5')
|
11
|
-
|
12
|
-
s.files = Dir["{lib,spec}/**/*", "[A-Z]*", "init.rb"]
|
13
|
-
s.require_path = "lib"
|
14
|
-
|
15
|
-
s.rubyforge_project = s.name
|
16
|
-
s.required_rubygems_version = ">= 1.3.4"
|
17
|
-
end
|