Class: Mongoid::Globalize::DocumentTranslation

Inherits:
Object
  • Object
show all
Includes:
Document
Defined in:
lib/mongoid_globalize/document_translation.rb

Overview

Base class for storing translations. All Translation classes are inherited from it.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.translated_klassObject

Accessor to document class which translated



11
12
13
# File 'lib/mongoid_globalize/document_translation.rb', line 11

def translated_klass
  @translated_klass
end

Class Method Details

.find_by_locale(locale) ⇒ Object

Returns translation document for given locale Param: String or Symbol - locale Return: Translation



31
32
33
# File 'lib/mongoid_globalize/document_translation.rb', line 31

def find_by_locale(locale)
  with_locale(locale.to_s).first
end

.translated_localesObject

Returns all locales used for translation. Return Array of Symbols



24
25
26
# File 'lib/mongoid_globalize/document_translation.rb', line 24

def translated_locales
  all.distinct("locale").sort{ |x,y| x.to_s <=> y.to_s }.map(&:to_sym)
end

.with_locales(*locales) ⇒ Object Also known as: with_locale

Scope for searching only in given locales Params: String or Symbol - locales Returns Mongoid::Criteria



16
17
18
19
# File 'lib/mongoid_globalize/document_translation.rb', line 16

def with_locales(*locales)
  locales = locales.flatten.map(&:to_s)
  where(:locale.in => locales)
end

Instance Method Details

#localeObject

Reader for locale attribute Return Symbol



38
39
40
# File 'lib/mongoid_globalize/document_translation.rb', line 38

def locale
  read_attribute(:locale).to_sym
end

#locale=(locale) ⇒ Object

Writer for locale attribute Param: String or Symbol - locale



44
45
46
# File 'lib/mongoid_globalize/document_translation.rb', line 44

def locale=(locale)
  write_attribute(:locale, locale.to_s)
end