2

コマンドラインツールを使用して、jinja2/coffin テンプレートを Babel で翻訳しようとしています。問題は、関数 babel_extract が {% url %} や {% csrf_token %} などの棺桶タグでジャムすることです。

まず、問題を検出するために、jinja.ext.babel_extract を変更し、レンダリング中の例外に「print e」を追加しました。

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

Babel で抽出メソッドを実行すると、次のエラーが出力されます。

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")

次に、babel 構成を編集して Coffin ライブラリを追加しました。また、環境変数を設定して、django プロジェクトを Python パスに追加し、django 設定モジュールを settings.py に設定しました。

[python: src/**.py]

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

[extractors]
jinja2 = jinja2.ext:babel_extract

ここで、extract メソッドを実行すると、次のエラーが発生します。

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)

4

0 に答える 0