[Django] #20811: Makemessages currently does not support alternative template languages

9 views
Skip to first unread message

Django

unread,
Jul 26, 2013, 4:55:37 PM7/26/13
to django-...@googlegroups.com
#20811: Makemessages currently does not support alternative template languages
------------------------------+-------------------------------
Reporter: cordery@… | Owner: nobody
Type: New feature | Status: new
Component: Translations | Version: master
Severity: Normal | Keywords: makemessages i18n
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
------------------------------+-------------------------------
Makemessages currently does not support alternative template languages, as
it uses open() directly and therefore does not give alternative template
languages the chance to preprocess templates. This seems an oversight as
alternative template languages seems to be intended to be supported by
Django, as discussed here
https://docs.djangoproject.com/en/dev/ref/templates/api/#using-an-
alternative-template-language

When using alternative template languages like hamlpy
(https://github.com/jessemiller/HamlPy), this prevents the templates from
being parsed for trans and blocktrans tags.

In hamlpy they tried to solve it by monkeypatching
django.utils.translation.trans_real.templatize but I think a better
solution would be add a function to the loader module,
get_template_source(), which operates using the same machinery as
get_template but returns source rather than the compiled template.
Makemessages could then use this new function to try to read each
discovered file using the template loaders, before resorting to open().

This would enable makemessages to properly find trans and blocktrans tags
in template files from other templating systems. For example in hamlpy
these tags might appear like this:


{{{
- trans "hello"
- blocktrans
This is a block trans'd string.
}}}

Which could not be read by makemessages. get_template_source would use
the hamlpy loader to load the template.haml file, and compile it to:

{{{
{% trans "hello"
{% blocktrans %}
This is a block trans'd string
{% endblocktrans %}
}}}

Which can be read by makemessages.

I will momentarily submit a pull request regarding this ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/20811>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 26, 2013, 5:00:11 PM7/26/13
to django-...@googlegroups.com
#20811: Makemessages currently does not support alternative template languages
-----------------------------------+--------------------------------------

Reporter: cordery@… | Owner: nobody
Type: New feature | Status: new
Component: Translations | Version: master
Severity: Normal | Resolution:

Keywords: makemessages i18n | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by cordery@…):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Patch here https://github.com/cordery/django/tree/ticket_20811

Will submit a pull request.

--
Ticket URL: <https://code.djangoproject.com/ticket/20811#comment:1>

Django

unread,
Aug 19, 2013, 1:30:55 PM8/19/13
to django-...@googlegroups.com
#20811: Makemessages currently does not support alternative template languages
-------------------------------------+-------------------------------------

Reporter: cordery@… | Owner: nobody
Type: New feature | Status: new
Component: | Version: master
Internationalization | Resolution:
Severity: Normal | Triage Stage:
Keywords: makemessages i18n | Unreviewed

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

* component: Translations => Internationalization


Comment:

[https://github.com/django/django/pull/1402 PR is here].

--
Ticket URL: <https://code.djangoproject.com/ticket/20811#comment:2>

Django

unread,
Aug 19, 2013, 4:22:07 PM8/19/13
to django-...@googlegroups.com
#20811: Makemessages currently does not support alternative template languages
-------------------------------------+-------------------------------------

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

Comment (by ramiro):

Some historical information for your review:

Back in the times, we used to have a get_template_source() method on
template loading backends.

They were removed with the refactoring work associated with the
introduction of template caching (#6262 / [44b9076bbe]).

After that, there was at least one report asking for its reintroduction:
#15102. Please don't take my commend on that ticket as a -1 to something
like this. At the time I didn't grasp how having an abstraction to get the
raw template source code could help in integrating other templating
languages.

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

Django

unread,
Aug 22, 2013, 11:24:29 PM8/22/13
to django-...@googlegroups.com
#20811: Makemessages currently does not support alternative template languages
-------------------------------------+-------------------------------------

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

Comment (by cordery@…):

Hamlpy gets around this by decorating
django.utils.translation.trans_real.templatize as seen here:
https://github.com/jessemiller/HamlPy/blob/master/hamlpy/templatize.py

Although note that this code is parsing all files instead of only those
with hamlpy extensions, so is actually broken when mutliple template
formats are used.

While this method is workable I feel that if Django wants to support other
template languages (many of which, like haml, are quite popular these
days), then a more consistent and intuitive approach would be to always
use the template loaders to load template files before trying a direct
open(), particularly in cases like makemessages where I assume performance
is not typically an issue.

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

Django

unread,
Oct 22, 2013, 2:47:49 PM10/22/13
to django-...@googlegroups.com
#20811: Makemessages currently does not support alternative template languages
--------------------------------------+------------------------------------

Reporter: cordery@… | Owner: nobody
Type: New feature | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: makemessages i18n | Triage Stage: Accepted

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

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/20811#comment:5>

Django

unread,
Jun 24, 2014, 9:09:08 PM6/24/14
to django-...@googlegroups.com
#20811: Makemessages currently does not support alternative template languages
--------------------------------------+------------------------------------

Reporter: cordery@… | Owner: nobody
Type: New feature | Status: new
Component: Internationalization | Version: master
Severity: Normal | Resolution:
Keywords: makemessages i18n | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/20811#comment:6>

Django

unread,
Jan 17, 2015, 3:26:16 AM1/17/15
to django-...@googlegroups.com
#20811: Makemessages currently does not support alternative template languages
--------------------------------------+------------------------------------
Reporter: cordery@… | Owner: nobody
Type: New feature | Status: closed
Component: Internationalization | Version: master
Severity: Normal | Resolution: wontfix

Keywords: makemessages i18n | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

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


Comment:

Given the implementation of multiple template engines that landed in
Django 1.8, Django template loaders aren't the right point to fix this
problem anymore. For this reason I'm closing the ticket.

Unfortunately internationalization didn't make it in Django 1.8. Further
work is tracked in 24167#.

--
Ticket URL: <https://code.djangoproject.com/ticket/20811#comment:7>

Reply all
Reply to author
Forward
0 new messages