python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.33k stars 444 forks source link

Unable to extract translation #882

Open ebanDev opened 2 years ago

ebanDev commented 2 years ago

Hello, when I'm tryna extract strings to translate from the following template : https://gitlab.ilearned.eu/i-learned/blog/theme/-/blob/localization/theme/templates/index.html I don't get any of those

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

Here is the command I'm using : pybabel extract --mapping babel.cfg --output messages.pot ./ My babel.cfg is [jinja2: templates/index.html] The strings are extracted from this file https://gitlab.ilearned.eu/i-learned/blog/theme/-/blob/localization/theme/templates/footer.html but it doesn't work for this one https://gitlab.ilearned.eu/i-learned/blog/theme/-/blob/localization/theme/templates/index.html it's kinda weird 😅 Thanks !

solsticedhiver commented 2 years ago

My guess would be because of your line 28 in your file

    <p>{% trans %}Lecture {{ article.readtime.minutes }}mn{% endtrans %}</p>

which includes a variable inside your string to translate, breaks pybabel.

First, you should try to render it, to see if jinja2 throws an error. Jinja2 is better at that than pybabel, that silently ignore the error wihtout telling you anythig about it.

Then, if it is confirmed, split your string in 2, putting your variable outside the string to translate.

That is an issue I just encounter, and pybabel is very wrong in the way it deals with this, because it does not signal the error, but then DO NOT extract any string from the file with the error.

This is very wrong. It should