Sha256: 0d125541374840e2bff0caac75242d5fe068b902978663ebfb9e962c8d2758bb
Contents?: true
Size: 1.78 KB
Versions: 9
Compression:
Stored size: 1.78 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: nation) else I18n.t("components.devolved_nations.type.publication", nation: nation) end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems