niwinz / django-jinja

Simple and nonobstructive jinja2 integration with Django.
http://niwinz.github.io/django-jinja/latest/
BSD 3-Clause "New" or "Revised" License
363 stars 102 forks source link

makemessages does not detect trimmed trans blocks #255

Closed canassa closed 4 years ago

canassa commented 4 years ago

Hello,

When I execute the makemessages command, it seems to be unable to detect trans tags that have the trimmed option in it. e.g.:

{% trans trimmed %}
  #{{ invoice_count }} invoice
{% pluralize %}
  #{{ invoice_count }} invoices
{% endtrans %}

If I remove the trimmed it works:

{% trans trimmed %}
  #{{ invoice_count }} invoice
{% pluralize %}
  #{{ invoice_count }} invoices
{% endtrans %}
wizpig64 commented 4 years ago

I'm working on a change to get this to work, but tests are showing my regex-fu is coming up short. I'll let you know if I can get this working.

wizpig64 commented 4 years ago

@canassa actually, i got the test suite's i18n template working, as well as makemessages to output.

It appears that, at least for this example, {% trans %} and {% trans trimmed %} blocks both get scanned correctly:

Do you have any other insight into your real world example that could make it not work?

canassa commented 4 years ago

Hmm, that's weird, I can reproduce the error even with your test template. I pasted your i18n_test.jinja in my project and it didn't generate the trimmed messages. Could it be due to some configuration on my project?

canassa commented 4 years ago

Note: the problem happens even without the plularize:

<p>
{% trans %}
  trans test
{% endtrans %}
</p>

</p>
{% trans trimmed %}
  trans test trimmed
{% endtrans %}
</p>
canassa commented 4 years ago

I did another test and I found out that it generates the message if I set the tag to {% trans trimmed=1 %} instead of {% trans trimmed %} (but the message is generated untrimmed of course)

wizpig64 commented 4 years ago

I pushed a regex change in 95e1f9 that relaxes the key=value bit. It doesn't change anything in my template test. Can you install that branch and let me know if it fixes it for you?

pip install -e git+https://github.com/wizpig64/django-jinja.git@95e1f91af7d28771e8f2ec90592bb64430903bd2#egg=django_jinja
canassa commented 4 years ago

Thanks! I will try it tonight and I let you know!

wizpig64 commented 4 years ago

@canassa were you able to verify that the above branch fixed your {% trans trimmed %} block issues? I'd like to submit a pull request with the changes, if they indeed fixed makemessages, before the next django-jinja release.

Thanks for your time.

canassa commented 4 years ago

Hey!

Sorry! I ended up forgetting to reply to you 😞

I tested the following scenarios:

{% trans %}
  teste 123
{% endtrans %}

{% trans trimmed=1 %}
  teste 123
{% endtrans %}

{% trans trimmed %}
  teste 123
{% endtrans %}

All are being detected now! And {% trans trimmed %} is correctly trimming the string.

Thanks!

wizpig64 commented 4 years ago

That's alright, thanks for your help!