Sha256: 7bc183c904796a589096879b5a12590c210c6377bf1c1b4a4117382ddaaa9fba

Contents?: true

Size: 1.07 KB

Versions: 12

Compression:

Stored size: 1.07 KB

Contents

module GOVUKDesignSystemFormBuilder
  module Traits
    module Localisation
    private

      def localised_text(context)
        key = localisation_key(context)

        return nil unless I18n.exists?(key)

        I18n.translate(key)
      end

      def localisation_key(context)
        return nil unless @object_name.present? && @attribute_name.present?

        schema(context)
      end

      def schema(context)
        schema_root(context)
          .push(@object_name, @attribute_name)
          .map { |e| e == :__context__ ? context : e }
          .join('.')
      end

      def schema_root(context)
        contextual_schema = case context
                            when :legend
                              config.localisation_schema_legend
                            when :hint
                              config.localisation_schema_hint
                            when :label
                              config.localisation_schema_label
                            end

        (contextual_schema || config.localisation_schema_fallback).dup
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
govuk_design_system_formbuilder-1.1.9 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.8 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.7 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.6 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.5 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.4 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.3 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.2 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.1 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.0 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.0.beta.3 lib/govuk_design_system_formbuilder/traits/localisation.rb
govuk_design_system_formbuilder-1.1.0.beta.2 lib/govuk_design_system_formbuilder/traits/localisation.rb