Sha256: 32de4fcd21e04aabc3793995853f0579298e4054f76277d3aee73ff9e003ebee
Contents?: true
Size: 1.31 KB
Versions: 24
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true module Decidim module Core # This type represents a translated field in multiple languages. class TranslatedFieldType < Decidim::Api::Types::BaseObject description "A translated field" field :locales, [GraphQL::Types::String, { null: true }], description: "Lists all the locales in which this translation is available", null: true field :translations, [LocalizedStringType, { null: true }], description: "All the localized strings for this translation.", null: false do argument :locales, [GraphQL::Types::String], description: "A list of locales to scope the translations to.", required: false end field :translation, GraphQL::Types::String, description: "Returns a single translation given a locale.", null: true do argument :locale, GraphQL::Types::String, "A locale to search for", required: true end def locales object.keys end def translation(locale: "") translations = object.stringify_keys translations[locale] end 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 end end end
Version data entries
24 entries across 24 versions & 1 rubygems