Skip to content

Add prettier-plugin-jinja-template - #3959

Merged
mathjazz merged 2 commits into
mozilla:mainfrom
dannycolin:gh3941
Feb 17, 2026
Merged

mathjazz merged 2 commits into
mozilla:mainfrom
dannycolin:gh3941

Conversation

@dannycolin

Copy link
Copy Markdown
Collaborator

Add a prettier parser for Pontoon jinja templates.

@mathjazz

Copy link
Copy Markdown
Collaborator

Nice work, Danny!

Please check the failing workflow.

@flodolo

flodolo commented Feb 10, 2026

Copy link
Copy Markdown
Collaborator

Worth noting that I see additional diff if I run make format locally with this PR.

Some of these errors (already closed html or tbody) feel off 🤔
For example, I can't spot a second </tbody> in team list.

@flodolo

flodolo commented Feb 10, 2026

Copy link
Copy Markdown
Collaborator

I checked again pontoon/teams/templates/teams/widgets/team_list.html, and I realized I have misread the error.

SyntaxError: Unexpected closing tag "tbody". It may happen when the tag has already been closed by another tag.

As @mathjazz pointed out while were discussing this, I think the problem is that there's a macro opening the <tbody> tag, then there's a second macro closing it, but the parser only knows about one macro at a time. So, either ignore the error or rewrite the template to have the full table markup within a macro.

@dannycolin

Copy link
Copy Markdown
Collaborator Author

@flodolo You're right. The parser works by:

  1. temporarily replace jinja with placeholders
  2. pipe the output to the html parser
  3. readd the jinja code

This means it's impossible to have separated opening/closing tags wrapped in a conditional (or macro) statement. It's also impossible to have tags partially generated by jinja (e.g. <h{{ level }}). Before I start fixing the linting errors, @mathjazz do you think it's still worth implementing knowing the parser limitations?

References:

@mathjazz mathjazz linked an issue Feb 11, 2026 that may be closed by this pull request
@mathjazz

Copy link
Copy Markdown
Collaborator

Before I start fixing the linting errors, @mathjazz do you think it's still worth implementing knowing the parser limitations?

It seems like there's just 9 files with errors in total? Some of the errors seem legit, others I'd fix by changing the structure or excluding the lines from formatting.

@dannycolin

Copy link
Copy Markdown
Collaborator Author

Before I start fixing the linting errors, @mathjazz do you think it's still worth implementing knowing the parser limitations?

It seems like there's just 9 files with errors in total? Some of the errors seem legit, others I'd fix by changing the structure or excluding the lines from formatting.

Yes, it was a mixed bag of errors (and fixes). I guess we should still file a bug to document the exceptions so ultimately we could fix them in a follow-up patch. It might even be a good-first-bug.

@flodolo

flodolo commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

In case, given how large the PR is

# git grep -l "prettier" -- '*.html'
pontoon/localizations/templates/localizations/widgets/resource_list.html
pontoon/projects/templates/projects/widgets/project_list.html
pontoon/tags/templates/tags/widgets/tag_list.html
pontoon/teams/templates/teams/widgets/team_list.html
translate/public/translate.html

I think it makes sense to keep those in a separate follow-up PR, as they require more work and better review.

}
</style>
</head>
{% block extend_css %}{% endblock %}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual fix (I think that's correct, and the block should be outside <style>).

{% set ids = notification.ids %}
{% set msg = notification.msg %}
<li><a href="{{ full_url('pontoon.translate', locale.code, project.slug, 'all-resources') }}?list={{ ids }}">{{
project.name }} ({{ locale.code }})</a>: {{ msg }}</a></li>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual error fixed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think the link should be on the first part, not also on message.

>{{ translation.locale.name }}</span
>
<span class="divider">&bull;</span>
<span class="translation-locale-code">{{ translation.locale.code }}</a>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another actual error.

@flodolo
flodolo requested a review from mathjazz February 12, 2026 08:15
@flodolo

flodolo commented Feb 12, 2026 •

Copy link
Copy Markdown
Collaborator

Unfortunately the UI with this branch is quite broken (projects, teams, contributors, tags within a project).

@flodolo

flodolo commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Heads-up: I'm going to push a fix for the broken templates, so that we can gain a few hours for testing.

<div class="total">
<span>All strings</span>
<p>{{ contributor.translations_count|intcomma }}</p>
</div><div class="approved">

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changing how the page looks like, because there's additional space between the divs.

Image

This PR requires some deep testing ☹️

<div
id="notifications"
class="notifications select{% if unread_count %}unread{% endif %}"
class="notifications select {% if unread_count %}unread{% endif %}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes

Image

@flodolo

flodolo commented Feb 12, 2026 •

Copy link
Copy Markdown
Collaborator

The latest version is deployed on DEV: https://pontoon.allizom.org/

@mathjazz

mathjazz commented Feb 12, 2026 •

Copy link
Copy Markdown
Collaborator

/search:

  • translation-header is repeated twice
Screenshot 2026-02-12 at 11 29 52

/messaging:

  • User roles are not checked by default

/contributors:

  • Translations header is not center-aligned

Team(s)/Project(s) Dashboards:

  • "Missing" icon in the top-left corner.
  • No bulb icon next to Unreviewed in the heading, and also not at the end of some rows (when pending suggestions are present). Seeing unreviewedpending and fa-lightbulbpending class names.
  • Space between title and the green asterisk in the heading.
Screenshot 2026-02-12 at 11 32 04

@flodolo

flodolo commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

"Missing" icon in the top-left corner.

Did you mean top right?

@flodolo

flodolo commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Space between title and the green asterisk in the heading.

I think we were relying on the lack of space between the two elements, used a negative margin (no clue if there's a better way).

I'll push the update to DEV server once the image is available.

@mathjazz

Copy link
Copy Markdown
Collaborator

"Missing" icon in the top-left corner.

Did you mean top right?

No. Updated the screenshot.

@flodolo

flodolo commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

No. Updated the screenshot.

Thanks. I don't see that on DEV. Do you still see it?
I also couldn't see it before, so I wonder if it depends on some specific on your profile.

@mathjazz

Copy link
Copy Markdown
Collaborator

It's fixed now.

Translation column in the seach page still breaks into the new line, though:
https://pontoon.allizom.org/search/?search=open&locale=sl

(we should use display:flex on parent or font-size:0).

I tested more (hopefully all) pages now, and these look different than on prod. Mostly it's the alignment of the right-most table header that is different. On the Premissions page entries for all projects are visible (even if not used).

https://pontoon.allizom.org/de/bugs/
https://pontoon.allizom.org/de/permissions/
https://pontoon.allizom.org/de/translation-memory/?search=open
https://pontoon.allizom.org/sl/amo/

@flodolo

flodolo commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

Haven't pushed yet to DEV, but the light-bulb in the table header is still broken on pontoon.allizom.org/sl/amo

@flodolo

flodolo commented Feb 12, 2026 •

Copy link
Copy Markdown
Collaborator

Not sure why https://pontoon.allizom.org/it/firefox/ looks so broken now (it works fine for me locally)

EDIT: that's because I don't have priority set on resources…

@flodolo

flodolo commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

I've checked with classes with directives, and couldn't find any more where the space was lost.

@mathjazz
You might want to double-check the CSS changes I made.

@mathjazz

Copy link
Copy Markdown
Collaborator

Nice work!

The only think that's off now is the table header appearing on https://pontoon.allizom.org/search/ even before you search.

@flodolo

flodolo commented Feb 12, 2026

Copy link
Copy Markdown
Collaborator

The only think that's off now is the table header appearing on pontoon.allizom.org/search even before you search.

giphy

Tested locally, not pushing to DEV again.

@dannycolin

Copy link
Copy Markdown
Collaborator Author

Thanks @flodolo for the help!

@flodolo

flodolo commented Feb 13, 2026

Copy link
Copy Markdown
Collaborator

Currently on DEV, clicking the notification bell in translate view crashes the front-end. What's weird is that it works just fine for me locally.

TypeError: can't access property "anchor", actor is null

@flodolo

flodolo commented Feb 13, 2026

Copy link
Copy Markdown
Collaborator

The crash on DEV is unrelated.

@flodolo

flodolo commented Feb 13, 2026 •

Copy link
Copy Markdown
Collaborator

I think there are still some issues with notifications (project name might be too close to the text, the baseline for links seems a bit higher than the normal text).

These are from main view

Screenshot 2026-02-13 alle 17 02 33 Screenshot 2026-02-13 alle 17 02 54

The vertical aligment seems to be a problem also in Translate view

Screenshot 2026-02-13 alle 17 04 30

@flodolo

flodolo commented Feb 13, 2026

Copy link
Copy Markdown
Collaborator

Starting to think the vertical misalignment is just an optical illusion

Screenshot 2026-02-13 alle 17 19 43

@dannycolin

Copy link
Copy Markdown
Collaborator Author

Starting to think the vertical misalignment is just an optical illusion
Screenshot 2026-02-13 alle 17 19 43

Yes, it is. Your brain is lying to you (mine too) :).

@flodolo

flodolo commented Feb 16, 2026

Copy link
Copy Markdown
Collaborator

Since I did a bit of back and forth on some parts, I reorganized the commits (@dannycolin work in one, my follow-up in a separate one) and rebased.

If we end up having to rebase this again, that should make things a bit easier.

@mathjazz mathjazz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hard work to both of you.

Especially to @dannycolin for taking this to the finish line and first contribution to Pontoon. Well done! 🥳

@mathjazz

Copy link
Copy Markdown
Collaborator

As agreed with @flodolo, let's merge this and put it to the DEV server for a day or two before shipping to prod.

@mathjazz
mathjazz merged commit de2d6d3 into mozilla:main Feb 17, 2026
7 checks passed
@functionzz

Copy link
Copy Markdown
Contributor

Thanks @dannycolin, this makes life easier :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce formatter for Jinja2 templates

4 participants