Class: ActionDispatch::Routing::Mapper::MappingLocalized

Inherits:
Mapping
  • Object
show all
Defined in:
lib/i18n_url/routes/mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(locale, set, scope, path, options) ⇒ MappingLocalized

Returns a new instance of MappingLocalized.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/i18n_url/routes/mapper.rb', line 30

def initialize(locale, set, scope, path, options)
  @locale = locale
  I18n.locale = locale
  path.gsub!(/^\//, '')
  format = '(.:format)'
  path.gsub!( format, '')   
  translate_route path
  path = "/#{@locale}/" + @localized_path.join("/")
  super(set, scope, path, options)
  localized_name_route
end

Instance Method Details

#localized_name_routeObject



42
43
44
45
# File 'lib/i18n_url/routes/mapper.rb', line 42

def localized_name_route
  original_name = @options[:as]
  @options[:as] = "#{@locale}_#{original_name}" if original_name
end

#translate_route(path) ⇒ Object



47
48
49
50
51
52
# File 'lib/i18n_url/routes/mapper.rb', line 47

def translate_route path
  path.split("/").each do |word|
    next if word[0] == ":"
    (@localized_path ||= []) << I18n.t(word,:scope => :routes, :default => word)
  end
end