MoritzS / jinja2-django-tags

jinja2 extensions that add django tags
MIT License
41 stars 11 forks source link

blocktrans is not compatible with Jinja2 version 3+ #13

Open M1ha-Shvn opened 2 years ago

M1ha-Shvn commented 2 years ago

Hi. When I updated jinja2 verion 3, templates using blocktrans started failing:

from django.template import engines
env = engines.all()[0].env
env.from_string("{% blocktrans %}test.key{% endblocktrans %}")

raises an error

Error
Traceback (most recent call last):
  File "/opt/project/tests/test_helpers.py", line 203, in test_without_nulls
    template = self.env.from_string("{% blocktrans %}test.key{% endblocktrans %}")
  File "/app/pip/lib/python3.10/site-packages/jinja2/environment.py", line 1092, in from_string
    return cls.from_code(self, self.compile(source), gs, None)
  File "/app/pip/lib/python3.10/site-packages/jinja2/environment.py", line 757, in compile
    self.handle_exception(source=source_hint)
  File "/app/pip/lib/python3.10/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<unknown>", line 1, in template
jinja2.exceptions.TemplateSyntaxError: unexpected end of template, expected 'end of statement block'.
M1ha-Shvn commented 2 weeks ago

Found out, that token.type is lexer.TOKEN_BLOCK_BEGIN doesn't work any more. Inside jinja parser it is compared as token.type == "block_trans". token.type == lexer.TOKEN_BLOCK_BEGIN also worked for me.

MoritzS commented 2 weeks ago

Hi Miha, thanks for reporting this! Feel free to open a merge request to fix this.