Skip to content

Flask jinja filter assets is incompatible with the pybabel command and fails to extract translations #108

@heartsucker

Description

@heartsucker

There's a chance I'm using this wrong, but I'm fairly certain this is a bug. If there is a better way to do this, it is certainly non-intuitive.

My setup

One html file called index.html. I extract with the command

pybabel extract -F babel.cfg --charset=utf=8 -o messages.pot --no-wrap index.html

The file bable.cfg

[jinja2: **.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_

My env:

(venv) heartsucker@pythagoras:~/Downloads/test$ python --version
Python 3.4.2
(venv) heartsucker@pythagoras:~/Downloads/test$ pip freeze
Babel==2.3.4
click==6.6
Flask==0.11.1
Flask-Babel==0.11.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
pytz==2016.6.1
Werkzeug==0.11.10
(venv) heartsucker@pythagoras:~/Downloads/test$ uname -a
Linux pythagoras 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 GNU/Linux
(venv) heartsucker@pythagoras:~/Downloads/test$ 

What works

If index.html is this:

<!DOCTYPE html>
<html>
  <head>
       <link rel="stylesheet" href="{{ ASSET_URL }}" />
  </head>
  <body>
    {{ gettext('Test') }}
  </body>
</html>

The messages.pot is this:

# Translations template for PROJECT.
# Copyright (C) 2016 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2016-08-25 21:57+0200\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 2.3.4\n"

#: index.html:7
msgid "Test"
msgstr ""

The one string called Test is correctly extract.

What doesn't work

If index.html is this:

<!DOCTYPE html>
<html>
  <head>
    {% assets filters="cssmin", output="gen/source.css", "css/normalize.css" %}
       <link rel="stylesheet" href="{{ ASSET_URL }}" />
    {% endassets %}
  </head>
  <body>
    {{ gettext('Test') }}
  </body>
</html>

The messages.pot is this:


# Translations template for PROJECT.
# Copyright (C) 2016 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2016.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2016-08-25 21:58+0200\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 2.3.4\n"

The one string called Test is not extract.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions