I'm having some problems getting Babel to extract internationalizable text
from Jinja2 templates.

Here's my setup: I've got a mymodule directory which contains an
__init__.py and a templates subdirectory which contains a Jinja2 template. See
the following shell session transcript:

#--------------------------------------------------------
vinay:~/projects/scratch$ ls mymodule
__init__.py  __init__.pyc  templates
vinay:~/projects/scratch$ cat mymodule/__init__.py
from gettext import gettext as _

def main():
    print(_('Hello, world!'))

if __name__ == "__main__":
    main()
vinay:~/projects/scratch$ ls mymodule/templates
index.html
vinay:~/projects/scratch$ cat mymodule/templates/index.html 
{% trans}This should be translatable.{% endtrans %}
#--------------------------------------------------------

Now, I create a clean virtualenv workspace (I'm using virtualenvwrapper):

#--------------------------------------------------------
vinay:~/projects/scratch$ mkvirtualenv scratch --no-site-packages
New python executable in scratch/bin/python
Installing setuptools............done.
vinay:~/projects/scratch$ workon scratch
#--------------------------------------------------------

I now install vanilla Babel and Jinja2 from PyPI.

#--------------------------------------------------------
(scratch)vinay:~/projects/scratch$ easy_install Babel Jinja2
[snip]
Finished processing dependencies for Babel
[snip]
Finished processing dependencies for Jinja2
#--------------------------------------------------------

I've got a babel.cfg file which specifies extraction of messages from Python
source and Jinja2 templates:

#--------------------------------------------------------
(scratch)vinay:~/projects/scratch$ cat babel.cfg
[python: **.py]

[jinja2: **/templates/**.html]
encoding = utf-8
#--------------------------------------------------------

I now try to extract messages:

#--------------------------------------------------------
(scratch)vinay:~/projects/scratch$ pybabel -v extract mymodule -o mymodule.pot
extracting messages from mymodule/__init__.py
writing PO template file to mymodule.pot
#--------------------------------------------------------

Note that Babel only appears to have extracted from __init__.py, and not from
the template. This is confirmed by looking at the POT file:

#--------------------------------------------------------
(scratch)vinay:~/projects/scratch$ cat mymodule.pot
# Translations template for PROJECT.
# Copyright (C) 2010 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <em...@address>, 2010.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: em...@address\n"
"POT-Creation-Date: 2010-02-16 10:39+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <em...@address>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.4\n"

#: mymodule/__init__.py:4
msgid "Hello, world!"
msgstr ""
#--------------------------------------------------------

Any ideas why the Jinja2 text isn't being extracted? It's probably something
simple that I've missed. All help gratefully received.

Regards,

Vinay Sajip


-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en.

Reply via email to