3

I'm trying to translate a jinja2/coffin template with Babel using the command line tool. The issue is that the function babel_extract jams on the coffin tags like {% url %} or {% csrf_token %}.

First, to detect the problem, I have modify jinja.ext.babel_extract and added "print e" on exceptions while rendering.

try:
    node = environment.parse(source)
    tokens = list(environment.lex(environment.preprocess(source)))
except TemplateSyntaxError, e:
    # skip templates with syntax errors
    print e
    return

When I run the extract method with Babel, it print out this error:

Encountered unknown tag 'url'. Jinja was looking for the following tags: 'endblock'. The innermost block that needs to be closed is 'block'. extracting messages from templates/contact.html (encoding="utf-8")

Then I have edit my babel config to add the Coffin Library. I have also set my environements variables to add my django project to my python path and set the django settings module to my settings.py.

[python: src/**.py]

[jinja2: templates/**.html]
encoding = utf-8
extensions = coffin.template.Library

[extractors]
jinja2 = jinja2.ext:babel_extract

Now, when I run the extract method, this error happens:

extracting messages from templates/brands.html (extensions="coffin.template.Library", encoding="utf-8") Traceback (most recent call last): File "/usr/local/bin/pybabel", line 9, in <module> load_entry_point('Babel==0.9.6', 'console_scripts', 'pybabel')() File "/Library/Python/2.7/site-packages/Babel-0.9.6-py2.7.egg/babel/messages/frontend.py", line 1107, in main return CommandLineInterface().run(sys.argv) File "/Library/Python/2.7/site-packages/Babel-0.9.6-py2.7.egg/babel/messages/frontend.py", line 651, in run return getattr(self, cmdname)(args[1:]) File "/Library/Python/2.7/site-packages/Babel-0.9.6-py2.7.egg/babel/messages/frontend.py", line 912, in extract for filename, lineno, message, comments in extracted: File "/Library/Python/2.7/site-packages/Babel-0.9.6-py2.7.egg/babel/messages/extract.py", line 171, in extract_from_dir strip_comment_tags): File "/Library/Python/2.7/site-packages/Babel-0.9.6-py2.7.egg/babel/messages/extract.py", line 201, in extract_from_file strip_comment_tags)) File "/Library/Python/2.7/site-packages/Babel-0.9.6-py2.7.egg/babel/messages/extract.py", line 275, in extract for lineno, funcname, messages, comments in results: File "/Library/Python/2.7/site-packages/jinja2/ext.py", line 588, in babel_extract auto_reload=False File "/Library/Python/2.7/site-packages/jinja2/environment.py", line 279, in __init__ self.extensions = load_extensions(self, extensions) File "/Library/Python/2.7/site-packages/jinja2/environment.py", line 76, in load_extensions result[extension.identifier] = extension(environment) TypeError: __init__() takes exactly 1 argument (2 given)

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
goodfriend0
  • 193
  • 1
  • 8

0 Answers0