Class: I18nRouting::LocalizedMapping

Inherits:
ActionDispatch::Routing::Mapper::Mapping
  • Object
show all
Defined in:
lib/i18n_routing_rails3.rb

Overview

Used for localize simple named routes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale, set, scope, args) ⇒ LocalizedMapping

Returns a new instance of LocalizedMapping.



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/i18n_routing_rails3.rb', line 276

def initialize(locale, set, scope, args)
  super(set, scope, args.clone)

  # try to get translated path :
  I18n.locale = locale
  ts = @path.gsub(/^\//, '')
  @localized_path = '/' + (I18nRouting.translation_for(ts, :named_routes_path) || ts)

  # If a translated path exists, set localized infos
  if @localized_path and @localized_path != @path
    #@options[:controller] ||= @options[:as]
    @options[:as] = "#{locale}_#{@options[:as]}"
    @path = @localized_path
    @options[:constraints] = @options[:constraints] ? @options[:constraints].dup : {}
    @options[:constraints][:i18n_locale] = locale.to_s
    @options[:anchor] = true
  else
    @localized_path = nil
  end

end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



274
275
276
# File 'lib/i18n_routing_rails3.rb', line 274

def path
  @path
end

Instance Method Details

#localizable?Boolean

Return true if this route is localizable

Returns:

  • (Boolean)


299
300
301
# File 'lib/i18n_routing_rails3.rb', line 299

def localizable?
  @localized_path != nil
end