Class: Decidim::Core::TranslatedFieldType

Inherits:
Api::Types::BaseObject
  • Object
show all
Defined in:
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 'lib/decidim/api/types/translated_field_type.rb', line 19

def locales
  object.keys
end

#translation(locale: "") ⇒ Object



23
24
25
26
# File '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 '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