Class: I18nRouting::LocalizedMapping
- Inherits:
-
ActionDispatch::Routing::Mapper::Mapping
- Object
- ActionDispatch::Routing::Mapper::Mapping
- I18nRouting::LocalizedMapping
- Defined in:
- lib/i18n_routing_rails3.rb
Overview
Used for localize simple named routes
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(locale, set, scope, path, options) ⇒ LocalizedMapping
constructor
A new instance of LocalizedMapping.
-
#localizable? ⇒ Boolean
Return true if this route is localizable.
Constructor Details
#initialize(locale, set, scope, path, options) ⇒ LocalizedMapping
Returns a new instance of LocalizedMapping.
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/i18n_routing_rails3.rb', line 288 def initialize(locale, set, scope, path, ) super(set, scope, path.clone, ? .clone : nil) stored_locale = I18n.locale # try to get translated path : I18n.locale = locale ts = @path.gsub(/^\//, '') ts.gsub!('(.:format)', '') tp = @options[:as] && I18nRouting.translation_for(@options[:as], :named_routes) || !ts.blank? && I18nRouting.translation_for(ts, :named_routes_path) || ts @localized_path = File.join((@scope[:path] || ''), tp).gsub(/\/$/, '') # If a translated path exists, set localized infos if !@localized_path.blank? and @localized_path != @path #@options[:controller] ||= @options[:as] @options[:as] = "#{I18nRouting.locale_escaped(locale)}_#{@options[:as]}" @path = @localized_path @options[:constraints] = @options[:constraints] ? @options[:constraints].dup : {} @options[:constraints][:i18n_locale] = locale.to_s @options[:anchor] = true # Force the recomputation of the requirements with the new values @requirements = nil else @localized_path = nil end I18n.locale = stored_locale end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
286 287 288 |
# File 'lib/i18n_routing_rails3.rb', line 286 def path @path end |
Instance Method Details
#localizable? ⇒ Boolean
Return true if this route is localizable
319 320 321 |
# File 'lib/i18n_routing_rails3.rb', line 319 def localizable? @localized_path != nil end |