Skip to content

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

  1. To introduce a ruby externalization helper that will allow developers to use basic HTML tags without submitting them for translation
  2. To introduce a similar helper for javascript externalization
  3. Update any existing strings to use these helpers
  4. 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

Action Items

  • Validate the solution we'd like to approach on the backend
  • Do a spike to make sure the approach is also feasible on the frontend
  • Based on the results, determine if both issues can be scheduled and ready for development in %13.1.
Edited by Josianne Hyson