Class: TranslationText

Inherits:
ApplicationRecord show all
Defined in:
app/models/translation_text.rb

Overview

== Schema Information

Table name: translation_texts
Database name: primary

id :bigint not null, primary key
last_accessed_at :datetime
locale :string not null
review_status :enum
text :text not null
created_at :datetime not null
updated_at :datetime not null
translation_key_id :integer not null

Indexes

index_translation_texts_on_translation_key_id_and_locale (translation_key_id,locale) UNIQUE

Foreign Keys

fk_rails_... (translation_key_id => translation_keys.id) ON DELETE => cascade

Constant Summary

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#localeString

Returns Normalized locale string.

Returns:

  • (String)

    Normalized locale string.



31
# File 'app/models/translation_text.rb', line 31

validates :locale, presence: true, uniqueness: { scope: :translation_key_id }

#textString

Returns Translated text.

Returns:

  • (String)

    Translated text.

Validations:



31
# File 'app/models/translation_text.rb', line 31

validates :locale, presence: true, uniqueness: { scope: :translation_key_id }

Class Method Details

.review_status_optionsArray<Array(String, Symbol)>

Returns:

  • (Array<Array(String, Symbol)>)


57
58
59
# File 'app/models/translation_text.rb', line 57

def self.review_status_options
  review_statuses.map { |n, _v| [n.to_s.humanize, n] }
end

Instance Method Details

#expire_cachevoid (protected)

This method returns an undefined value.



52
53
54
# File 'app/models/translation_text.rb', line 52

def expire_cache
  FastGettext.expire_cache_for(translation_key.key)
end

#normalize_localeString (protected)

We apply a gettext normalization to our locale, e.g en-US is stored as en_US

Returns:

  • (String)


47
48
49
# File 'app/models/translation_text.rb', line 47

def normalize_locale
  self.locale = TranslationKey.normalize_locale(locale)
end

#translation_keyTranslationKey

Returns:



25
# File 'app/models/translation_text.rb', line 25

belongs_to :translation_key, class_name: 'TranslationKey', touch: true