Skip to content


Babel doesn't extract messages when "with" tag used #172

seriyps opened this Issue · 1 comment

2 participants


(Flask==0.9, if relevant)

$ ls
babel.cfg  bad.html  good.html  output.pot

$ cat babel.cfg
[python: **.py]
[jinja2: **.html]
[jinja2: **.txt]

$ cat bad.html
    <title>{%trans%}My bad title{%endtrans%}</title>
    {% with foo=42 %}
      {{foo}} {%trans%}My bad foo{%endtrans%}
    {% endwith %}
  {%trans%}My bad footer{%endtrans%}

$ cat good.html
    <title>{%trans%}My good title{%endtrans%}</title>
    {# % with foo=42 % #}
      {{foo}} {%trans%}My good foo{%endtrans%}
    {# % endwith % #}
  {%trans%}My good footer{%endtrans%}

$ pybabel extract -F babel.cfg -o output.pot ./
extracting messages from bad.html
extracting messages from good.html
writing PO template file to output.pot

$ cat output.pot
# Translations template for PROJECT.
# Copyright (C) 2013 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2013-01-14 05:18+0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.6\n"

#: good.html:3
msgid "My good title"
msgstr ""

#: good.html:7
msgid "My good foo"
msgstr ""

#: good.html:9
msgid "My good footer"
msgstr ""

As you see, output.pot contains only phrases from good.html, bad.html was inspected, but no phrases were added from it.
Note, that jinja2.ext.with_ enabled in babel.cfg


You only have the extensions enabled for *.txt not for *.html.

@mitsuhiko mitsuhiko closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.