Class: Mongoid::Globalize::DocumentTranslation
- Inherits:
-
Object
- Object
- Mongoid::Globalize::DocumentTranslation
- 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
-
.translated_klass ⇒ Object
Accessor to document class which translated.
Class Method Summary collapse
-
.find_by_locale(locale) ⇒ Object
Returns translation document for given locale Param: String or Symbol - locale Return: Translation.
-
.translated_locales ⇒ Object
Returns all locales used for translation.
-
.with_locales(*locales) ⇒ Object
(also: with_locale)
Scope for searching only in given locales Params: String or Symbol - locales Returns Mongoid::Criteria.
Instance Method Summary collapse
-
#locale ⇒ Object
Reader for
locale
attribute Return Symbol. -
#locale=(locale) ⇒ Object
Writer for
locale
attribute Param: String or Symbol - locale.
Class Attribute Details
.translated_klass ⇒ Object
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_locales ⇒ Object
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
#locale ⇒ Object
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 |