ditch fe jinja2 filter and use Jinja2 newstyle gettext instead

RESOLVED WONTFIX

Status

Mozilla QA
One and Done
P3
normal
RESOLVED WONTFIX
2 years ago
a year ago

People

(Reporter: bsilverberg, Unassigned)

Tracking

Version 4
Milestone 1

Details

(Reporter)

Description

2 years ago
+++ This bug was initially created as a clone of Bug #1222040 +++

Fjord has an fe (format escaped) filter that we inherited from Tower that allows us to do the following in templates:

    {{ _('Response: {id}')|fe(id=response.id) }}


In this expression, gettext is called with the msgid "Response: {id}" and it returns a translated form of that string. The resulting string is marked as Jinja2-safe by Fjord's adjusted gettext, so nothing is escaped in this string.

Then the string is passed to the fe filter which evaluates response.id in the context, escapes that value and then interpolates it into the string using Python's .format().

Yay! This is what we want!

However, there are two problems.

1. fe requires that we use python-brace-format (e.g. {}) variables which
   we want to get rid of (bug #1220657)

2. Jinja2's newstyle gettext already does this:

   {{ _('Response: %(id)s', id=response.id) }}


Here's a more complex example.

With fe:

   <h2>{{ _('<b>Response id: {id}</b>')|fe(id='<i>102</i>') }}</h2>

This comes out as:

   <b>Response id: &lt;i&gt;102&lt;/i&gt;</b>

where the <b> </b> is not escaped and the <i> </i> are.

The equivalent with newstyle gettext:

   <h2>{{ _('<b>Response id: %(id)s</b>', id='<i>102</i>') }}</h2>

produces the same thing.


This bug covers getting rid of our fe filter in favor of Jinja2's newstyle gettext.
(Reporter)

Updated

2 years ago
No longer blocks: 1220657
No longer depends on: 1222040, 1218381
Priority: -- → P3
Target Milestone: --- → Milestone 3
(Reporter)

Updated

2 years ago
Target Milestone: Milestone 3 → Milestone 1
Version: Version 3 → Version 4
Project is being retired.
Status: NEW → RESOLVED
Last Resolved: a year ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.