babel
babel copied to clipboard
Unable to extract translation
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 <[email protected]>\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 !
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
- signal the error
- and/or extract the other strings from the file
@akx Could this be labeled and re-titled? Sadly I can't help with that but I'll help with the issue :-)
<p>{% trans %}Lecture {{ article.readtime.minutes }}mn{% endtrans %}</p>
is indeed wrong – as described in the documentation for Jinja's i18n tags, you would need to bind any "complex" variable tags within the block like
<p>{% trans duration=article.readtime.minutes %}Lecture {{ duration }}mn{% endtrans %}</p>
As for Jinja extraction behavior, it's not maintained in this repo, but over at Jinja's.
Looks like you can set a silent = false flag for it to be louder about these issues.