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.



307
308
309
# File 'lib/i18n_routing_rails3.rb', line 307

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.



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/i18n_routing_rails3.rb', line 315

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', 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



309
310
311
# File 'lib/i18n_routing_rails3.rb', line 309

def set_localizable_route(localizable)
  @localizable = localizable
end