Module: RailsI18nRoutes::ActionDispatch::Mapper

Defined in:
lib/rails_i18n_routes/action_dispatch/mapper.rb

Instance Method Summary collapse

Instance Method Details

#add_route(action, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rails_i18n_routes/action_dispatch/mapper.rb', line 19

def add_route(action, options)
 if @locales
    @locales.each do |locale|
      path = @scope[:path].dup if @scope[:path].present?
      path_names = @scope[:path_names].dup
      @scope[:path] = i18n_path(path, locale) if @scope[:path].present?
      @scope[:path_names].each { |key, value| @scope[:path_names][key] = I18n.t("routes.#{key}", :locale => locale, :default => value) }
      super(*[i18n_path(action, locale), i18n_options(options, locale)])
      @scope[:path] = path if @scope[:path].present?
      @scope[:path_names] = path_names
    end
    @set.named_routes.define_i18n_route_helper @scope[:as] ? "#{@scope[:as]}_#{options[:as]}" : options[:as] unless @scope[:scope_level_resource].present?
    return
  end
  super
end

#localizedObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rails_i18n_routes/action_dispatch/mapper.rb', line 5

def localized
  @locales = I18n.available_locales.dup
  case Rails.application.config.i18n_routes.selection
  when :prefix
    scope ':locale' do
      yield
    end
  when :subdomain
    @locales.shift # For some reason :en is always there          
    yield
  end    
  @locales = nil # Needed to routes below localize block to work
end