Module: IsTranslatable::Methods::InstanceMethods
- Defined in:
- lib/is_translatable.rb
Instance Method Summary collapse
- #get_translation(kind, locale = nil) ⇒ Object
- #remove_translation(kind, locale = nil) ⇒ Object
- #set_translation(kind, t, locale = nil) ⇒ Object
Instance Method Details
#get_translation(kind, locale = nil) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/is_translatable.rb', line 41 def get_translation(kind, locale=nil) validate_kind(kind) locale ||= I18n.locale return read_attribute(kind) if locale.to_s == I18n.default_locale.to_s t = translations.find_by_kind(kind.to_s, :conditions => {:locale => locale.to_s}) t ||= find_translation(kind, locale) t.translation unless t.nil? end |
#remove_translation(kind, locale = nil) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/is_translatable.rb', line 50 def remove_translation(kind, locale = nil) validate_kind(kind) locale ||= I18n.locale t = find_translation(kind, locale) t.mark_for_destruction unless t.nil? end |
#set_translation(kind, t, locale = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/is_translatable.rb', line 26 def set_translation(kind, t, locale=nil) validate_kind(kind) locale ||= I18n.locale if locale.to_s == I18n.default_locale.to_s write_attribute(kind, t) return end t_obj = find_translation(kind, locale) if t_obj.nil? translations.build({:kind => kind.to_s, :translation => t, :locale => locale.to_s}) else t_obj.translation = t end end |