Module: I18nRouting::NamedRouteCollection

Defined in:
lib/i18n_routing_rails3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#localizableObject (readonly)

Returns the value of attribute localizable.



325
326
327
# File 'lib/i18n_routing_rails3.rb', line 325

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.



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/i18n_routing_rails3.rb', line 333

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



327
328
329
# File 'lib/i18n_routing_rails3.rb', line 327

def set_localizable_route(localizable)
  @localizable = localizable
end