Class: Decidim::Core::TranslatedFieldType

Inherits:
Api::Types::BaseObject show all
Defined in:
decidim-core/lib/decidim/api/types/translated_field_type.rb

Overview

This type represents a translated field in multiple languages.

Instance Method Summary collapse

Instance Method Details

#localesObject


19
20
21
# File 'decidim-core/lib/decidim/api/types/translated_field_type.rb', line 19

def locales
  object.keys
end

#translation(locale: "") ⇒ Object


23
24
25
26
# File 'decidim-core/lib/decidim/api/types/translated_field_type.rb', line 23

def translation(locale: "")
  translations = object.stringify_keys
  translations[locale]
end

#translations(locales: []) ⇒ Object


28
29
30
31
32
33
# File 'decidim-core/lib/decidim/api/types/translated_field_type.rb', line 28

def translations(locales: [])
  translations = object.stringify_keys
  translations = translations.slice(*locales) unless locales.empty?

  translations.map { |locale, text| OpenStruct.new(locale: locale, text: text) }
end