Class: TranslationKey

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/fast_gettext/translation_repository/db_models/translation_key.rb

Class Method Summary collapse

Class Method Details

.available_localesObject



22
23
24
25
26
27
28
29
30
# File 'lib/fast_gettext/translation_repository/db_models/translation_key.rb', line 22

def self.available_locales
  @available_locales ||= begin
    if ActiveRecord::VERSION::MAJOR >= 3
      TranslationText.group(:locale).count
    else
      TranslationText.count(group: :locale)
    end.keys.sort
  end
end

.newline_normalize(string) ⇒ Object



32
33
34
# File 'lib/fast_gettext/translation_repository/db_models/translation_key.rb', line 32

def self.newline_normalize(string)
  string.to_s.gsub("\r\n", "\n")
end

.translation(key, locale) ⇒ Object



15
16
17
18
19
20
# File 'lib/fast_gettext/translation_repository/db_models/translation_key.rb', line 15

def self.translation(key, locale)
  return unless translation_key = find_by_key(newline_normalize(key))
  return unless translation_text = translation_key.translations.find_by_locale(locale)

  translation_text.text
end