The change is very small, it uses findall instead of match, that allows
finding inner _() function calls that are very common in jinja2 templates
(and not in django templates):
https://github.com/niwibe/django/compare/interoprability-jinja-django-
i18n-parse
--
Ticket URL: <https://code.djangoproject.com/ticket/23299>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Hi,
Can you show some examples of use-cases that are made possible by your
change (these would be useful as testcases if we were to include the
feature anyway).
For reference, I just checked your patch against Django's test suite and
it doesn't seem to break anything which is a good sign.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:1>
Comment (by gandriyko):
Expample, when use Jinj2
When run '''django-admin.py makemessages -l uk'''
its collect fine items like '''{{ _('Index') }}'''
but item '''<th>{{ table_sort('date_start', _('Year')) }}</th>''' not
working.
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:2>
* cc: template-refactor (added)
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:3>
* cc: template-refactor (removed)
* keywords: => template-refactor
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:4>
Comment (by aaugustin):
I believe this is a duplicate of #12377 which was closed as wontfix long
ago.
But we're going to need this as part of my plan to support multiple
template engines.
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:5>
* status: new => closed
* resolution: => wontfix
Comment:
The approach proposed here is too simple. It won't work with arbitrary
template engines (eg. XML-based). Django needs proper extensibility.
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:6>
Comment (by niwibe):
I understand that django needs proper extensibility and obviously, my
purpose fix only a little interoperability problem.
But the purposed change is very small, not affects to existing code and
helps a lot to people that uses jinja with django. Please reconsider apply
the change.
I don't think that it can disturb while django extensibility is solved...
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:7>
Comment (by aaugustin):
It will be solved in Django 1.8, unless my Multiple Template Engines for
Django project fails. If that happens, we can reopen this ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:8>
* status: closed => new
* resolution: wontfix =>
Comment:
Reopening because I will include this as a stopgap solution in Django 1.8
until #24167 can be tackled.
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:9>
* status: new => assigned
* owner: nobody => aaugustin
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:10>
Comment (by aaugustin):
I extracted all translation constructs from examples given in Jinja2's
documentation:
{{{
<p>{% trans %}1 Hello {{ user }}!{% endtrans %}</p>
<p>{% trans user=user.username %}2 Hello {{ user }}!{% endtrans %}</p>
{% trans book_title=book.title, author=author.name %}
3 This is {{ book_title }} by {{ author }}
{% endtrans %}
{% trans count=list|length %}
4 There is {{ count }} {{ name }} object.
{% pluralize %}
4 There are {{ count }} {{ name }} objects.
{% endtrans %}
{{ _('5 Hello World!') }}
{{ _('6 Hello %(user)s!')|format(user=user.username) }}
{{ gettext('7 Hello World!') }}
{{ gettext('8 Hello %(name)s!', name='World') }}
{{ ngettext('9 %(num)d apple', '9 %(num)d apples', apples|count) }}
}}}
(Numbers added to make strings unique.)
The change proposed in the patch doesn't cover them.
It doesn't seem reasonable to me to attempt to support both Django and
Jinja2 syntax with a single regex-based parser, all the more since the {%
trans %} tag has different syntax in the two languages.
Perhaps the right solution for Django 1.8 is to tell people to use Babel.
I haven't benchmarked its features against makemessages yet.
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:11>
Comment (by MoritzS):
There is also the possibility to write extensions for jinja2 that add the
i18n tags with django's syntax so makemessages detects them.
I did a proof of concept of this and also added some other django-only
tags:
https://github.com/MoritzS/jinja2-django-tags
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:12>
* cc: MoritzS (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:13>
Comment (by aaugustin):
So, we've documented Babel as the recommended solution in 1.8, and not
gotten negative feedback until now.
What about closing this ticket as wontfix?
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:14>
* status: assigned => closed
* resolution: => wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:15>