Closed Bug 1225161 Opened 9 years ago Closed 9 years ago

ditch fe jinja2 filter and use Jinja2 newstyle gettext instead

Categories

(developer.mozilla.org Graveyard :: Code Cleanup, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: robhudson, Assigned: robhudson)

References

Details

+++ 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.
Assignee: nobody → robhudson
No longer blocks: 1220657
No longer depends on: 1222040, 1218381
Blocks: 1209185
Commits pushed to master at https://github.com/mozilla/kuma

https://github.com/mozilla/kuma/commit/a9c7acd289f8d8d0b0e6702e473b1fae94ba852a
Fix bug 1225161 - Use newstyle gettext in favor of |f and |fe

https://github.com/mozilla/kuma/commit/4838c29847fa6f58935ceefb2a23a641df4e0ad2
Merge pull request #3654 from robhudson/1225161-no-jingo-filters

Fix bug 1225161 - Use newstyle gettext in favor of |f and |fe
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Product: developer.mozilla.org → developer.mozilla.org Graveyard
You need to log in before you can comment on or make changes to this bug.