Sha256: f80beb0ccb49801bb3c7a95282b40de5d09ff94cfbbafdfe9c46082443224084

Contents?: true

Size: 1.76 KB

Versions: 99

Compression:

Stored size: 1.76 KB

Contents

module GovukPublishingComponents
  module Presenters
    class DevolvedNationsHelper
      attr_reader :national_applicability, :type

      def initialize(local_assigns)
        @national_applicability = local_assigns[:national_applicability]
        @type = local_assigns[:type] || "publication"
      end

      def applicable_nations_title_text(use_english_translation = nil)
        @national_applicability
          .select { |_, v| v[:applicable] == true }
          .map { |k, _| get_translation("components.devolved_nations.#{k}", use_english_translation) }
          .sort
          .to_sentence(
            two_words_connector: get_translation("components.devolved_nations.connectors.two_words", use_english_translation),
            last_word_connector: get_translation("components.devolved_nations.connectors.last_word", use_english_translation),
          )
      end

      def get_translation(key, use_english_translation = nil)
        return I18n.t(key, locale: :en) if use_english_translation

        I18n.t(key)
      end

      def ga4_applicable_nations_title_text(remove_connector_word = nil)
        return applicable_nations_title_text(true).gsub(" and", ",") if remove_connector_word

        applicable_nations_title_text(true)
      end

      def nations_with_urls
        @national_applicability
          .select do |_, v|
            v[:alternative_url]
            .present?
          end
      end

      def alternative_content_text(name)
        nation = I18n.t("components.devolved_nations.#{name}")

        if I18n.exists?("components.devolved_nations.type.#{@type}")
          I18n.t("components.devolved_nations.type.#{@type}", nation:)
        else
          I18n.t("components.devolved_nations.type.publication", nation:)
        end
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
govuk_publishing_components-38.0.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.10.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.9.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.9.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.8.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.8.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.7.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.7.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.6.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.6.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.5.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.5.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.4.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.3.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.3.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.2.4 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.2.3 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.2.2 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.2.1 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
govuk_publishing_components-37.2.0 lib/govuk_publishing_components/presenters/devolved_nations_helper.rb