Search code examples
pythoninternationalizationtranslationtornado

Extract translations from tornado template


I'm trying to use python-babel to extract translations from tornado templates.

I have tried some solutions, and none of them is perfect.

solution one

Use python as extractor:

# babel.cfg
[python: **/server/templates/**.html]

It works most of time, but won't work if there are some translations inside script blocks:

<script> var a = {{ _("won't be extracted") }} </script>

solution two

Just let tornado use jinja2 template engine, it works but not pretty.

solution three

Use tornado-babel, it is just an outdated library without python3 support.


Any suggestion?


Solution

  • Finally, I just use jinja2 template engine. Highly recommend tornado's team to use jinja2 template engine! Do not waste time any more.