Add translation helper for using HTML tags in externalized strings
This issue is intended to address part of https://gitlab.com/gitlab-org/gitlab/-/issues/19485
It is the follow up issue to https://gitlab.com/gitlab-org/gitlab/-/issues/217933 where we disallowed HTML tags in externalized strings.
Goals
- To introduce a ruby externalization helper that will allow developers to use basic HTML tags without submitting them for translation
- To introduce a similar helper for javascript externalization
- Update any existing strings to use these helpers
- Update documentation and communicate changes to the dev team if necessary
Planned Approach:
Basic Usage:
html_(s_("Namespace|Example string with some %{strongTagOpen}strong%{strongTagClose} text"))
# => 'Example string with some <strong>strong</strong> text'
The html_()
method can substitute in the <strong>
tags (and a small set of accepted tags) by default. It will also call html_escape
(or equivalent in js
) to ensure that the string does not contain unescaped characters.
Usage with attributes:
For examples where we need additional attributes we could have tag generator helpers, like described in: https://gitlab.com/gitlab-org/gitlab/-/issues/19485#note_215045602
zones_link_info = translated_link_to("zones", zones_path, class: 'btn')
# => { 'zones_link_start' => '<a href="/zones" class="btn">', 'zones_link_end' => '</a>' }
# And can be used as:
_("Learn more about %{zone_link_start}zones%{zone_link_end}") % zone_link_info