Module: Skyline::TranslationHelper
- Defined in:
- app/helpers/skyline/translation_helper.rb
Instance Method Summary collapse
-
#t(key, options = {}) ⇒ Object
- Extended translate function ==== Parameters key<Symbol,String>
- the key (same as parameter to translate function) options
options(same as parameter to translate function) this function supports a Class in the options, ie: tx(:ueber, :scope => [Skyline::Page, :flashes]) will try to translate this for Skyline::Page and all its parent classes (all descendants from AR) first try: translate(:ueber, :scope => [:page, :flashes]) if that fails, it'll try: translate(:ueber, :scope => [:article, :flashes]) (note that the Skyline module is stripped) if no Class is found, we'll fallback on the super function.
- the key (same as parameter to translate function) options
Instance Method Details
#t(key, options = {}) ⇒ Object
Extended translate function
Parameters
- key<Symbol,String>
the key (same as parameter to translate function)
- options
options(same as parameter to translate function) this function supports a Class in the options, ie: tx(:ueber, :scope => [Skyline::Page, :flashes]) will try to translate this for Skyline::Page and all its parent classes (all descendants from AR) first try: translate(:ueber, :scope => [:page, :flashes]) if that fails, it'll try: translate(:ueber, :scope => [:article, :flashes]) (note that the Skyline module is stripped) if no Class is found, we'll fallback on the super function
Returns
the translation
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/skyline/translation_helper.rb', line 17 def t(key, = {}) klass = [:scope] && [:scope].kind_of?(Array) && [:scope].detect{|s| s.kind_of?(Class)} return super unless klass klass_index = [:scope].index(klass) [:raise] = true klass.self_and_descendants_from_active_record.map do |superklass| begin o = .dup o[:scope][klass_index] = superklass.name.underscore.sub(/^skyline\//, "") return I18n.translate(key, o) rescue I18n::MissingTranslationData => e end end super end |