Skip to content

Replace angle brackets in frontend translations with entity codes

Josianne Hyson requested to merge jh-replace_js_angle_brackets into master

What does this MR do?

Replace the use of angle brackets in the final strings on the HTML todolist. Merging this will mean we can remove the TODO list functionality and can continue to translate all our strings normally.

Both of these strings we tricky to get working, and the approaches were chosen for the following reasons:

Related Issues Box

Replacing the </> with &lt; and &gt; does not work in this scenario because of the way Vue sets attributes on a placeholder text (using setAttribute). The result of the substitution is outputting these strings looking like this:

"or &lt;#issue id&glt;"

This is illustrated here: https://jsfiddle.net/rf5esptd/

Replacing these characters with the JS versions of these entities (x3C and \x3E) results in the frontend output being correct. However, the gettext extractor we're using currently un-escapes these characters when collating the PO file, so we still submit < and > for translation. This is a bug/new feature that is in progress here:

For now, as these are only presentation related, I have chosen to extract them from the string and substitute them back in with variables. This should still be safe as we validate that the variable count in the source and translated strings are the same.

Analytics Page

For this string I couldn't find a sensible way to work around using the v-html tag. We need the &lt; sign to go to translation because this symbol is different in some languages (ie currently our translation for this in Japanese is "1 時間未満").

But if we insert this without rendering it as HTML, Vue will escape the code and render it incorrectly. Maybe this is something we can extend GlSprintf helper to handle in the future?

Screenshots

screen screenshot
related issues Screen_Shot_2020-08-26_at_3.45.38_PM Screen_Shot_2020-08-26_at_3.55.11_PM
analytics Screen_Shot_2020-08-27_at_1.53.29_PM

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • ~~Label as security and @ mention @gitlab-com/gl-security/appsec~~
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Josianne Hyson

Merge request reports

Loading