Module: Locomotive::Extensions::ContentEntry::Localized
- Included in:
- ContentEntry
- Defined in:
- app/models/locomotive/extensions/content_entry/localized.rb
Instance Method Summary collapse
-
#localized? ⇒ Boolean
Tell if the entry is localized or not, meaning if the label field is localized or not.
-
#translated? ⇒ Boolean
Tell if the content entry has been translated or not.
-
#translated_field?(field_or_name) ⇒ Boolean
Tell if the field of the content entry has been translated in the current locale or not.
-
#translated_in ⇒ Array
Return the locales the content entry has been translated to.
Instance Method Details
#localized? ⇒ Boolean
Tell if the entry is localized or not, meaning if the label field is localized or not.
55 56 57 |
# File 'app/models/locomotive/extensions/content_entry/localized.rb', line 55 def localized? self.respond_to?(:"#{self._label_field_name}_translations") end |
#translated? ⇒ Boolean
Tell if the content entry has been translated or not. It just checks if the field used for the label has been translated. It assumes the entry is localized.
12 13 14 15 16 17 18 |
# File 'app/models/locomotive/extensions/content_entry/localized.rb', line 12 def translated? if self.respond_to?(:"#{self._label_field_name}_translations") self.send(:"#{self._label_field_name}_translations").key?(::Mongoid::Fields::I18n.locale.to_s) #rescue false else true end end |
#translated_field?(field_or_name) ⇒ Boolean
Tell if the field of the content entry has been translated in the current locale or not.
39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/locomotive/extensions/content_entry/localized.rb', line 39 def translated_field?(field_or_name) field = field_or_name.respond_to?(:name) ? field_or_name : self.fields[field_or_name.to_s] if field.try(:localized?) locale = ::Mongoid::Fields::I18n.locale.to_s (self.attributes[field.name] || {}).key?(locale) else nil end end |
#translated_in ⇒ Array
Return the locales the content entry has been translated to.
24 25 26 27 28 29 30 |
# File 'app/models/locomotive/extensions/content_entry/localized.rb', line 24 def translated_in if self.localized? self.send(:"#{self._label_field_name}_translations").keys else nil end end |