Open patrickpatrickpatrick opened 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"}, )) %>
+1 to Max's approach
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 inen.yml
.The instances of html in locale files are as follows:
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 beand then a helper method could be used to assemble the link.