Module: I18nRouting
- Defined in:
- lib/i18n_routing_common.rb,
lib/i18n_routing_rails3.rb
Overview
I18nRouting module for common usage methods
Defined Under Namespace
Modules: Mapper, NamedRouteCollection, RackMountRoute Classes: LocalizedMapping
Constant Summary collapse
- DefaultPathNames =
[:new, :edit]
- PathNamesKeys =
[:path_names, :member, :collection]
Class Method Summary collapse
-
.path_names(name, options) ⇒ Object
Return path names hash for given resource.
-
.translation_for(name, type = :resources, option = nil) ⇒ Object
Return the correct translation for given values.
Class Method Details
.path_names(name, options) ⇒ Object
Return path names hash for given resource
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/i18n_routing_common.rb', line 30 def self.path_names(name, ) h = ([:path_names] || {}).dup path_names = DefaultPathNames PathNamesKeys.each do |v| path_names += [v].keys if [v] and Hash === [v] end path_names.each do |pn| n = translation_for(name, :path_names, pn) n = nil if n == pn.to_s # Get default path_names in path_names scope if no path_names found n ||= I18n.t(pn, :scope => :path_names, :default => name.to_s) h[pn] = n if n and n != name.to_s end return h end |
.translation_for(name, type = :resources, option = nil) ⇒ Object
Return the correct translation for given values
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/i18n_routing_common.rb', line 6 def self.translation_for(name, type = :resources, option = nil) # First, if an option is given, try to get the translation in the routes scope if option default = "{option}Noi18nRoutingTranslation" t = I18n.t(option, :scope => "routes.#{name}.#{type}", :default => default) return (t == default ? nil : t) else default = "{name}Noi18nRoutingTranslation" # Try to get the translation in routes namescope first t = I18n.t(:as, :scope => "routes.#{name}", :default => default) return t if t and t != default t = I18n.t(name.to_s, :scope => type, :default => default) return (t == default ? nil : t) end end |