Module: SimpleModelTranslations::Base

Defined in:
lib/simple_model_translations/base.rb

Instance Method Summary collapse

Instance Method Details

#translates(*attributes, &block) ⇒ Object

Configure translated attributes. Eg: class Post < ActiveRecord::Base

translates :title, :description, :attributes => true

end



20
21
22
23
24
25
26
# File 'lib/simple_model_translations/base.rb', line 20

def translates(*attributes, &block)
  configure_translations(attributes.extract_options!)
  translation_class.class_eval(&block) if block_given?

  delegate *(attributes + [:to => 'translation_helper.current_translation'.to_sym, :allow_nil => true])
  delegate *(attributes.map { |attr| "#{attr}=" } + [:to => 'translation_helper.find_or_build_current_translation'.to_sym])
end

#translation_for(model) ⇒ Object

Configure translation model dependency. Eg: class PostTranslation < ActiveRecord::Base

translation_for :post

end



9
10
11
12
13
# File 'lib/simple_model_translations/base.rb', line 9

def translation_for(model)
  belongs_to model
  validates_presence_of :locale
  validates_uniqueness_of :locale, :scope => "#{model}_id"
end