alphagov / govuk_publishing_components

A gem to document and distribute frontend components for GOV.UK applications
https://components.publishing.service.gov.uk
MIT License
66 stars 20 forks source link

Several Instances of HTML in locale files #2780

Open patrickpatrickpatrick opened 2 years ago

patrickpatrickpatrick commented 2 years ago

What

Remove all instances of HTML in locale files.

Why

When I was working on a card to add data-tracking attributes to the copyright and license links in the footer, I noticed that the actual elements I was to add data to were actually in the locale files themselves. I was able to add a listener to the container of the link but to me it seems quite unmaintainable to have essentially 60 copies of the same elements with different text. If a class needed to be changed or an attribute then something could easily be missed. In fact there is already an issue caused by this - the a element in copyright_html links to a 404 in every other language apart from in en.yml.

The instances of html in locale files are as follows:

opendocument_html: This file is in an <a href='https://www.gov.uk/guidance/using-open-document-formats-odf-in-your-organisation' target=%{target} class='govuk-link'>OpenDocument</a> format

request_format_details_html: If you use assistive technology (such as a screen reader) and need a version of this document in a more accessible format, please email <a href='mailto:%{alternative_format_contact_email}' target='_blank' class='govuk-link'>%{alternative_format_contact_email}</a>. Please tell us what format you need. It will help us if you say what assistive technology you use.

phase_banner_html: This is a new service – your <a class="govuk-link" href="https://signin.account.gov.uk/contact-us?supportType=PUBLIC">feedback</a> will help us to improve it.

copyright_html: <a class="govuk-footer__link govuk-footer__copyright-logo" href="https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/">© Crown copyright</a>

licence_html: All content is available under the <a class="govuk-footer__link" href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" rel="license">Open Government Licence v3.0</a>, except where otherwise stated

It seems to me that most of these have the same format of prefix link suffix, so perhaps an alternative structure for this pattern could be

licence_link
    prefix: All content is available under the 
    link_text: Open Government Licence v3.0
    suffix: except where otherwise stated

and then a helper method could be used to assemble the link.

maxgds commented 2 years ago

I disagree with the suggested solution of prefix/link text/suffix because grammar would potentially break if you were doing clean exact string translations of sentence fragments. There are some options discussed on stackoverflow here: https://stackoverflow.com/questions/2543936/rails-i18n-translating-text-with-links-inside

If this only affects links we could probably get away with something like:

open_doc_message: "This file is in an %{open_doc_link_text} format." open_doc_link_text: "link"

<%= t("open_doc_message", href: link_to(t("open_doc_link_text"), "https://www.gov.uk/guidance/using-open-document-formats-odf-in-your-organisation", {class:"classname", data: "data-attrib"}, )) %>

chao-xian commented 2 years ago

+1 to Max's approach