module Para::I18n::Model::ClassMethods

Public Instance Methods

translates(*fields) click to toggle source
# File lib/para/i18n/model.rb, line 85
def translates(*fields)
  self.translated_attribute_names = fields.map(&:to_sym)
  self.translatable = true

  fields.each do |field|
    prepare_attribute_translation(field)
  end

  define_method(:_disabled_for_locale) do
    read_translated_attribute(:_disabled_for_locale) == "1"
  end

  define_method(:_disabled_for_locale=) do |value|
    write_translated_attribute(:_disabled_for_locale, value)
  end
end
translates?() click to toggle source
# File lib/para/i18n/model.rb, line 102
def translates?
  translatable
end

Private Instance Methods

prepare_attribute_translation(attribute) click to toggle source
# File lib/para/i18n/model.rb, line 108
def prepare_attribute_translation(attribute)
  # Let the Para::I18n::AttributeTranslation::Attachment module handle
  # ActiveStorage attachment fields translation preparation.
  Para::I18n::AttributeTranslation::Attachment.prepare(self, attribute)

  define_method(attribute) do
    read_translated_attribute(attribute)
  end

  define_method(:"#{attribute}=") do |value|
    write_translated_attribute(attribute, value)
  end
end