[Django] #23299: Add some interoperability to _() function calls parsing in templatize function.

18 views
Skip to first unread message

Django

unread,
Aug 15, 2014, 3:41:21 PM8/15/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
--------------------------------------+--------------------
Reporter: niwibe | Owner: nobody
Type: New feature | Status: new
Component: Internationalization | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
The current implementation only works for django and works very well. But
for make easy use another template engine like jinja2 and combine it with
django i18n makemessages process, would be awesome include some support
for more generic parsing of _() function calls.

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.

Django

unread,
Aug 16, 2014, 11:07:09 AM8/16/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
-------------------------------------+-------------------------------------

Reporter: niwibe | Owner: nobody
Type: New feature | Status: new
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* 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>

Django

unread,
Aug 18, 2014, 7:19:52 AM8/18/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
-------------------------------------+-------------------------------------

Reporter: niwibe | Owner: nobody
Type: New feature | Status: new
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Oct 1, 2014, 12:40:38 PM10/1/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
--------------------------------------+------------------------------------

Reporter: niwibe | Owner: nobody
Type: New feature | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* cc: template-refactor (added)
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:3>

Django

unread,
Oct 1, 2014, 12:40:48 PM10/1/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
--------------------------------------+------------------------------------

Reporter: niwibe | Owner: nobody
Type: New feature | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: template-refactor | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* cc: template-refactor (removed)
* keywords: => template-refactor


--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:4>

Django

unread,
Oct 18, 2014, 1:11:27 PM10/18/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
--------------------------------------+------------------------------------

Reporter: niwibe | Owner: nobody
Type: New feature | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Nov 1, 2014, 3:40:18 AM11/1/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
--------------------------------------+------------------------------------
Reporter: niwibe | Owner: nobody
Type: New feature | Status: closed
Component: Internationalization | Version: master
Severity: Normal | Resolution: wontfix

Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by aaugustin):

* 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>

Django

unread,
Nov 1, 2014, 5:25:44 AM11/1/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
--------------------------------------+------------------------------------
Reporter: niwibe | Owner: nobody
Type: New feature | Status: closed
Component: Internationalization | Version: master

Severity: Normal | Resolution: wontfix
Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Nov 1, 2014, 5:34:56 AM11/1/14
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
--------------------------------------+------------------------------------
Reporter: niwibe | Owner: nobody
Type: New feature | Status: closed
Component: Internationalization | Version: master

Severity: Normal | Resolution: wontfix
Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Jan 17, 2015, 3:25:59 AM1/17/15
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
--------------------------------------+------------------------------------

Reporter: niwibe | Owner: nobody
Type: New feature | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:

Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by aaugustin):

* 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>

Django

unread,
Jan 17, 2015, 3:26:47 AM1/17/15
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
-------------------------------------+-------------------------------------
Reporter: niwibe | Owner: aaugustin
Type: New feature | Status: assigned
Component: | Version: master
Internationalization |

Severity: Normal | Resolution:
Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* status: new => assigned
* owner: nobody => aaugustin


--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:10>

Django

unread,
Jan 23, 2015, 4:35:44 PM1/23/15
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
-------------------------------------+-------------------------------------
Reporter: niwibe | Owner: aaugustin
Type: New feature | Status: assigned
Component: | Version: master
Internationalization |
Severity: Normal | Resolution:
Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Mar 14, 2015, 7:08:31 AM3/14/15
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
-------------------------------------+-------------------------------------
Reporter: niwibe | Owner: aaugustin
Type: New feature | Status: assigned
Component: | Version: master
Internationalization |
Severity: Normal | Resolution:
Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Mar 14, 2015, 7:12:52 AM3/14/15
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
-------------------------------------+-------------------------------------
Reporter: niwibe | Owner: aaugustin
Type: New feature | Status: assigned
Component: | Version: master
Internationalization |
Severity: Normal | Resolution:
Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by MoritzS):

* cc: MoritzS (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:13>

Django

unread,
May 3, 2015, 3:29:46 PM5/3/15
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
-------------------------------------+-------------------------------------
Reporter: niwibe | Owner: aaugustin
Type: New feature | Status: assigned
Component: | Version: master
Internationalization |
Severity: Normal | Resolution:
Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 17, 2015, 8:34:23 AM5/17/15
to django-...@googlegroups.com
#23299: Add some interoperability to _() function calls parsing in templatize
function.
-------------------------------------+-------------------------------------
Reporter: niwibe | Owner: aaugustin
Type: New feature | Status: closed
Component: | Version: master
Internationalization |
Severity: Normal | Resolution: wontfix

Keywords: template-refactor | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* status: assigned => closed
* resolution: => wontfix


--
Ticket URL: <https://code.djangoproject.com/ticket/23299#comment:15>

Reply all
Reply to author
Forward
0 new messages