-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do we use the templatize function ? #96
Comments
I'm not familiar with the templatize function and I have been wondering what it's all about when looking through the code. Just going to tag @culebron on this to see if he can fill us in! |
I've dug deeper in the code, and there is a separate class, whose name is hard-coded in the template engine, that converts templates into somithng python-like, where everything except {% trans '' %} becomes letter "X". As I remember, you need to inherit the whole chain of classes from loader to template and parser, to replace a single function in Parser. I also ended making a shell script:
|
There is a very simple solution: django-admin.py makemessages --settings=[project.settings] -a -e haml,html Where:
|
I've been digging into this quite a bit. BackgroundBasically, when makemessages is run, django uses a function called templatize (django.utils.translation.trans_real.templatize) to turn the django template code into something xgettext can read. Hamlpy monkeypatches that function in hamlpy.templatize to ensure that hamlpy reads the source and converts it first.
If you do not trigger this monkeypatching, makemessages will not read your haml templates properly, particularly it will not parse blocktrans contents. I think a better fix would be if django used the template loaders when calling makemessages instead of just using open(). I've submitted an issue about this https://code.djangoproject.com/ticket/20811 Getting makemessages to work properlyTo get makemessages to work (mostly, see next section) properly simply add the following line to your to your settings.py
Alternately, you could write a wrapper for makemessages. You could also just add import hamlpy as hamlpy.init calls import templatize on line 1, but I like to keep things explicit when monkeypatching. Getting makemessages to work with multiple template formats (haml, html, txt, etc)You will notice that the monkeypatch does not try to first determine whether the file is haml or not. This means that non haml files may choke with errors like
This is caused by templates like the following, where parts are being misread as haml. In the following example the hyphens are misinterpreted as a haml command even though this is a .txt not a .haml
To avoid this you will need to modify the monkeypatch by doing something like this gist https://gist.github.com/cordery/6315117 |
Fix to templatize decorator so it only hamlpy parses files with valid haml extensions see Issue #96
Thanks @cordery the import statement in settings.py works like a charm. |
Hello,
Great app you made here, i'm using it in most of my projects now.
I saw there is a templatize function in the project, it seems to link the haml processing to the translations utility.
After looking in the issues already here I found the #40 but i didn't understand how to use it.
My solution is for now is simple, but integrating yours would be a big enhancement.
The text was updated successfully, but these errors were encountered: