Module: TranslatableAttributes::InstanceMethods

Defined in:
lib/translatable_attributes.rb

Instance Method Summary collapse

Instance Method Details

#save_translatable_attributesObject



63
64
65
66
67
68
69
70
# File 'lib/translatable_attributes.rb', line 63

def save_translatable_attributes
  @translatable_attribute_records.each do |locale, records|
    records.each do |attr, record|
      record.key = translatable_attribute_record_key(attr)
      record.save!
    end
  end unless @translatable_attribute_records.nil?
end

#translatable_attribute_record(attr, locale) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/translatable_attributes.rb', line 76

def translatable_attribute_record(attr, locale)
  key = translatable_attribute_record_key(attr)
  @translatable_attribute_records ||= {}
  @translatable_attribute_records[locale] ||= {}
  @translatable_attribute_records[locale][attr] ||= I18n::Backend::ActiveRecord::Translation.locale(locale).find_by_key(key)
  @translatable_attribute_records[locale][attr] ||= I18n::Backend::ActiveRecord::Translation.locale(locale).build
end

#translatable_attribute_record_key(attr) ⇒ Object



72
73
74
# File 'lib/translatable_attributes.rb', line 72

def translatable_attribute_record_key(attr)
  "#{self.class.name.demodulize.tableize}.#{to_param}.#{attr}"
end