class Mongoid::Globalize::DocumentTranslation
Base class for storing translations. All Translation classes are inherited from it.
Attributes
translated_klass[RW]
Accessor to document class which translated
Public Class Methods
find_by_locale(locale)
click to toggle source
Returns translation document for given locale Param: String or Symbol - locale Return: Translation
# File lib/mongoid_globalize/document_translation.rb, line 31 def find_by_locale(locale) with_locale(locale.to_s).first end
translated_locales()
click to toggle source
Returns all locales used for translation. Return Array of Symbols
# 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)
click to toggle source
Scope for searching only in given locales Params: String or Symbol - locales Returns Mongoid::Criteria
# File lib/mongoid_globalize/document_translation.rb, line 16 def with_locales(*locales) locales = locales.flatten.map(&:to_s) where(:locale.in => locales) end
Also aliased as: with_locale
Public Instance Methods
locale()
click to toggle source
Reader for locale
attribute Return Symbol
# File lib/mongoid_globalize/document_translation.rb, line 38 def locale read_attribute(:locale).to_sym end
locale=(locale)
click to toggle source
Writer for locale
attribute Param: String or Symbol - locale
# File lib/mongoid_globalize/document_translation.rb, line 44 def locale=(locale) write_attribute(:locale, locale.to_s) end