Class: TranslationCenter::Translation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TranslationCenter::Translation
- Defined in:
- app/models/translation_center/translation.rb
Constant Summary collapse
- CHANGES_PER_PAGE =
5
- NUMBER_PER_PAGE =
15
Class Method Summary collapse
- .accepted(translation_key_id) ⇒ Object
-
.recent_changes ⇒ Object
gets recent changes on translations TODO: remove this method as it is not being used elsewhere.
Instance Method Summary collapse
-
#accept ⇒ Object
accept translation by changing its status and if there is an accepting translation make it pending.
-
#accepted? ⇒ Boolean
returns true if the status of the translation is accepted.
-
#notify_key ⇒ Object
called before destory to update the key status.
-
#one_translation_per_lang_per_key ⇒ Object
make sure user has one translation per key per lang.
-
#pending? ⇒ Boolean
returns true if the status of the translation is pending.
-
#unaccept ⇒ Object
unaccept a translation.
-
#update_key_status ⇒ Object
called after save to update the key status.
Class Method Details
.accepted(translation_key_id) ⇒ Object
34 35 36 |
# File 'app/models/translation_center/translation.rb', line 34 def self.accepted(translation_key_id) where(status: 'accepted', translation_key_id: translation_key_id) end |
.recent_changes ⇒ Object
gets recent changes on translations TODO: remove this method as it is not being used elsewhere
79 80 81 |
# File 'app/models/translation_center/translation.rb', line 79 def self.recent_changes Audited::Adapters::ActiveRecord::Audit.where('auditable_type = ?', 'TranslationCenter::Translation').search(params).relation.reorder('created_at DESC') end |
Instance Method Details
#accept ⇒ Object
accept translation by changing its status and if there is an accepting translation make it pending
61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/translation_center/translation.rb', line 61 def accept # if translation is accepted do nothing unless self.accepted? self.translation_key.accepted_translation_in(self.lang).try(:update_attribute, :status, 'pending') # reload the translation key as it has changed self.translation_key.reload self.update_attribute(:status, 'accepted') end end |
#accepted? ⇒ Boolean
returns true if the status of the translation is accepted
50 51 52 |
# File 'app/models/translation_center/translation.rb', line 50 def accepted? self.status == 'accepted' end |
#notify_key ⇒ Object
called before destory to update the key status
44 45 46 47 |
# File 'app/models/translation_center/translation.rb', line 44 def notify_key self.key.update_status self.lang self.audits.destroy_all end |
#one_translation_per_lang_per_key ⇒ Object
make sure user has one translation per key per lang
84 85 86 87 88 89 90 91 |
# File 'app/models/translation_center/translation.rb', line 84 def one_translation_per_lang_per_key if Translation.where(lang: self.lang, translator_id: self.translator.id, translator_type: self.translator.class.name, translation_key_id: self.key.id).empty? true else false self.errors.add(:lang, I18n.t('.one_translation_per_lang_per_key')) end end |
#pending? ⇒ Boolean
returns true if the status of the translation is pending
55 56 57 |
# File 'app/models/translation_center/translation.rb', line 55 def pending? self.status == 'pending' end |
#unaccept ⇒ Object
unaccept a translation
73 74 75 |
# File 'app/models/translation_center/translation.rb', line 73 def unaccept self.update_attribute(:status, 'pending') end |
#update_key_status ⇒ Object
called after save to update the key status
39 40 41 |
# File 'app/models/translation_center/translation.rb', line 39 def update_key_status self.key.update_status self.lang end |