Module: I18nRouting::NamedRouteCollection

Defined in:
lib/i18n_routing_rails31.rb,
lib/i18n_routing_rails32.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#localizableObject (readonly)

Returns the value of attribute localizable.



348
349
350
# File 'lib/i18n_routing_rails31.rb', line 348

def localizable
  @localizable
end

Instance Method Details

#define_localized_url_helper(route, name, kind, options) ⇒ Object

Alias named route helper in order to check if a localized helper exists If not use the standard one.



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/i18n_routing_rails31.rb', line 356

def define_localized_url_helper(route, name, kind, options)
  if n = localizable
    selector = url_helper_name(name, kind)

    rlang = if n.kind_of?(ActionDispatch::Routing::Mapper::Resources::Resource) and i = name.to_s.rindex("_#{n.plural}")
              "#{selector.to_s[0, i]}_glang_#{n.plural}#{selector.to_s[i + "_#{n.plural}".size, selector.to_s.size]}"
            elsif n.kind_of?(ActionDispatch::Routing::Mapper::Resources::Resource) and i = name.to_s.rindex("_#{n.singular}")
              "#{selector.to_s[0, i]}_glang_#{n.singular}#{selector.to_s[i + "_#{n.singular}".size, selector.to_s.size]}"
            else
              "glang_#{selector}"
            end

    @module.module_eval <<-end_eval # We use module_eval to avoid leaks
      alias_method :localized_#{selector}, :#{selector}

      def #{selector}(*args)
        selector_g = '#{rlang}'.gsub('glang', I18nRouting.locale_escaped(I18n.locale.to_s)).to_sym

        #puts "Call routes : #{selector} => \#{selector_g} (\#{I18n.locale}) "
        if respond_to? selector_g and selector_g != :#{selector}
          send(selector_g, *args)
        else
          localized_#{selector}(*args)
        end
      end

    end_eval

  end
end

#set_localizable_route(localizable) ⇒ Object



350
351
352
# File 'lib/i18n_routing_rails31.rb', line 350

def set_localizable_route(localizable)
  @localizable = localizable
end