Module: FormTranslation::ForModel::ClassMethods
- Defined in:
- lib/form_translation/for_model.rb
Instance Method Summary collapse
-
#create_translated_getters(methods) ⇒ Object
translate_me.
- #translate_me(*methods) ⇒ Object
-
#translation_names_for(*attributes) ⇒ Object
create_translated_getters.
Instance Method Details
#create_translated_getters(methods) ⇒ Object
translate_me
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/form_translation/for_model.rb', line 53 def create_translated_getters(methods) mod = Module.new methods.each do |nam| mod.send(:define_method, nam) do return super() unless self.class.form_translation_locale return super() if self.class.form_translation_locale == FormTranslation.default_language a = self.send "#{self.class.form_translation_locale}_#{nam}" a.presence || self[nam] end # define_method end #methods.each prepend mod end |
#translate_me(*methods) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/form_translation/for_model.rb', line 29 def translate_me *methods store FormTranslation.translation_column methods.each do |m| FormTranslation.foreign_languages.each do |l| store_accessor FormTranslation.translation_column, "#{l}_#{m}".to_sym end end self.class.class_exec do define_method :translated_attrs do methods end define_method :form_translations do FormTranslation.foreign_languages.collect do |f| methods.collect do |m| "#{f}_#{m}".to_sym end end.flatten end end create_translated_getters(methods) end |
#translation_names_for(*attributes) ⇒ Object
create_translated_getters
67 68 69 70 71 72 73 |
# File 'lib/form_translation/for_model.rb', line 67 def translation_names_for *attributes Array(attributes).flatten.collect do |a| FormTranslation.foreign_languages.collect do |f| "#{f}_#{a}".to_sym end end.flatten end |