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.
* 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>
* component: Translations => Internationalization
Comment:
[https://github.com/django/django/pull/1402 PR is here].
--
Ticket URL: <https://code.djangoproject.com/ticket/20811#comment:2>
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>
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>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/20811#comment:5>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/20811#comment:6>
* 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>