ditch fe jinja2 filter and use Jinja2 newstyle gettext instead

RESOLVED WONTFIX

Status

Input Graveyard
Code Quality
RESOLVED WONTFIX
2 years ago
10 months ago

People

(Reporter: willkg, Unassigned)

Tracking

Details

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.
This blocks bug #1220657. Pretty sure these are the only strings in templates that are using python-brace-format variables. Fixing this probably require translation work, so we'll need to have both the old and new strings in for a while until things are translated.

Of course, in order to know whether things are translated, we need bug #1218381 fixed first. Making this depend on that.
Blocks: 1220657
Depends on: 1218381
Blocks: 1222336
No longer blocks: 1222336
Blocks: 1225161
No longer blocks: 1225161
Blocks: 1226592
No longer blocks: 1226592
The Input service has been decommissioned (see bug 1315316) and has been replaced by a redirect to an external vendor (SurveyGizmo). I'm bulk WONTFIXing Input bugs that do not appear to be relevant anymore.
Status: NEW → RESOLVED
Last Resolved: 10 months ago
Resolution: --- → WONTFIX
(Assignee)

Updated

10 months ago
Product: Input → Input Graveyard
You need to log in before you can comment on or make changes to this bug.