12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/translatable_routes/action_dispatch/mapper.rb', line 12
def add_route(action, options)
if @locales
@locales.each do |locale|
if @scope[:scope_level_resource] && resource_method_scope?
original_scope_level_resource = @scope[:scope_level_resource].dup
end
if @scope[:path]
original_path = @scope[:path].dup
end
original_path_names = @scope[:path_names].dup
original_options = options.dup
@scope[:path] = i18n_path(@scope[:path], locale)
@scope[:path_names].each do |key, value|
@scope[:path_names][key] = i18n_path(value, locale)
end
options[:path] = i18n_path(options[:path], locale)
(options[:constraints] ||= {}).merge!(locale: locale.to_s)
(options[:defaults] ||= {}).merge!(locale: locale.to_s)
if @scope[:scope_level_resource] && resource_method_scope?
resource = @scope[:scope_level_resource].dup
%w(collection_name member_name).each do |method|
resource.class_eval do
define_method method do
"#{super()}_#{locale}"
end
end
end
@scope[:scope_level_resource] = resource
else
options[:as] = "#{options[:as] || action}_#{locale}"
end
super i18n_path(action, locale), options
if @scope[:scope_level_resource] && resource_method_scope?
@scope[:scope_level_resource] = original_scope_level_resource
end
if @scope[:path]
@scope[:path] = original_path
end
@scope[:path_names] = original_path_names
options = original_options
end
if @scope[:scope_level_resource] && resource_method_scope?
helper = name_for_action(options[:as], action)
@set.named_routes.define_i18n_url_helper helper
else
helper = "#{options[:as] || action}"
if @scope[:as]
helper.prepend "#{@scope[:as]}_"
end
@set.named_routes.define_i18n_url_helper helper
end
else
super
end
end
|