Skip to content

Loading…

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

Closed
seriyps opened this Issue · 1 comment

2 participants

@seriyps

Jinja2==2.6
Babel==0.9.6
(Flask==0.9, if relevant)

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

$ cat babel.cfg
[python: **.py]
[jinja2: **.html]
[jinja2: **.txt]
extensions=jinja2.ext.autoescape,jinja2.ext.with_

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

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

$ 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.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2013.
#
#, 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 <LL@li.org>\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

@mitsuhiko
Owner

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.