Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with makemessages after updating to django-jinja 2.7.0 #272

Closed
pacahon opened this issue Feb 12, 2021 · 6 comments · Fixed by #273
Closed

Problem with makemessages after updating to django-jinja 2.7.0 #272

pacahon opened this issue Feb 12, 2021 · 6 comments · Fixed by #273
Labels

Comments

@pacahon
Copy link

pacahon commented Feb 12, 2021

Hello.

Looks like it's impossible to use {% trans myvar %} syntax in DTL files after this change e3764f6 was introduced.

@auvipy
Copy link
Collaborator

auvipy commented Feb 12, 2021

@wizpig64 can you check please?

@hugokernel
Copy link

Same problem here.

Could you check please.

@wizpig64
Copy link
Collaborator

wizpig64 commented Feb 18, 2021

TL;DR workaround for django 3.1 users:

Django 3.1 renamed the trans tag family to translate, but kept the old tags around for compatibility with old templates.

If you are using django 3.1 or higher, convert your DLT templates to use {% translate myvar %} instead of {% trans myvar %}, and things ought to work again using the current django-jinja 2.7.0.


exhaustive explanation:

I was able to replicate this issue by converting the repo's i18n_test.jinja to DTL. At first it looked like nothing was wrong, but after re-reading the ticket I realized I was using {% translate %} and not {% trans %}. switching got it to raise the initially-misleading message SyntaxError: Translation blocks must not include other block tags: trans 'Year' as t_year (file testapp/templates/i18n_test.html, line 6).

Here's what's happening in this particular failure: Django is trying to prevent nested {% blocktrans(late) %}/{% endblocktrans(late) %} blocks, but the name of jinja's equivalent to these ({% trans %}/{% endtrans %}) collides with django's standalone {% trans myvar %} tag. Because our monkey patched makemessages command processes both types of templates with the same collection of regexes, and I was unaware of this at the time of 2.7.0, my faulty regex change treated a DTL {% trans myvar %} tag like a {% blocktrans(late) %} tag, which breaks things as it expects a closing {% endblocktrans(late) %}.

My new regex uses a different approach to solve #255 that seems to work with the right tags in the right engines.

@wizpig64
Copy link
Collaborator

@pacahon @hugokernel I've submitted a change that fixed this in my test template, and should not necessitate upgrading to the translate tag as above. Please test it out with your templates, as they might break differently than mine did.

@hugokernel
Copy link

@pacahon @hugokernel I've submitted a change that fixed this in my test template, and should not necessitate upgrading to the translate tag as above. Please test it out with your templates, as they might break differently than mine did.

I had try the new regexp and it works well.

Thx

@pacahon
Copy link
Author

pacahon commented Feb 19, 2021

It works for me too. Thanks.

@wizpig64 wizpig64 mentioned this issue Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants