Module: Locomotive::Extensions::ContentEntry::Localized
- Extended by:
- ActiveSupport::Concern
- 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.
67 68 69 |
# File 'app/models/locomotive/extensions/content_entry/localized.rb', line 67 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.
24 25 26 27 28 29 30 |
# File 'app/models/locomotive/extensions/content_entry/localized.rb', line 24 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.
51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/locomotive/extensions/content_entry/localized.rb', line 51 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.
36 37 38 39 40 41 42 |
# File 'app/models/locomotive/extensions/content_entry/localized.rb', line 36 def translated_in if self.localized? self.send(:"#{self._label_field_name}_translations").keys else nil end end |