Module: IsTranslatable::Methods::InstanceMethods

Defined in:
lib/is_translatable.rb

Instance Method Summary collapse

Instance Method Details

#get_translation(kind, locale = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/is_translatable.rb', line 37

def get_translation(kind, locale=nil)
  validate_kind(kind)
  locale ||= I18n.locale
  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



45
46
47
48
49
50
# File 'lib/is_translatable.rb', line 45

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
# File 'lib/is_translatable.rb', line 26

def set_translation(kind, t, locale=nil)
  validate_kind(kind)
  locale ||= I18n.locale
  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