Class: TranslationCenter::Translation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/translation_center/translation.rb

Constant Summary collapse

CHANGES_PER_PAGE =
5
NUMBER_PER_PAGE =
15

Class Method Summary collapse

Instance Method Summary collapse

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_changesObject

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

#acceptObject

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

Returns:

  • (Boolean)


50
51
52
# File 'app/models/translation_center/translation.rb', line 50

def accepted?
  self.status == 'accepted'
end

#notify_keyObject

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_keyObject

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

Returns:

  • (Boolean)


55
56
57
# File 'app/models/translation_center/translation.rb', line 55

def pending?
  self.status == 'pending'
end

#unacceptObject

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_statusObject

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