ITADN

extract: keywords treated correctly as CLI args, but incorrect in pybabel.cfg

#1224Openvioluke 创建于 2025-08-18
bugarea/messages
V
violukecommented
I think this is a bug, but it could be me doing something wrong. Assume that the file `app/data/PaymentMethods.py` contains: ```python from django.db import models from django.utils.translation import gettext_lazy as _l class PaymentMethodIntegerChoices(models.IntegerChoices): PAYMENT_METHOD_CASH = 1, _l("Cash") PAYMENT_METHOD_CARD = 2, _l("Card") PAYMENT_METHOD_CHEQUE = 3, _l("Cheque") PAYMENT_METHOD_DIRECT_DEBIT = 4, _l("Direct Debit") PAYMENT_METHOD_BANK_TRANSFER = 5, _l("Bank Transfer") ``` If I have this `pybabel.cfg`: ```cfg # Extraction from Python source files [python: **.py] encoding = utf-8 keywords = _ _l _n:1,2 _nl:1,2 _p:1c,2 _pl:1c,2 _np:1c,2,3 _npl:1c,2,3 add_comments = Translators: width = 300 ``` And then run this command ```bash pybabel extract -F babel.cfg -o template.pot app/data/PaymentMethods.py ``` I get no translatable string in `template.pot`: ``` # Translations template for PROJECT. # Copyright (C) 2025 ORGANIZATION # This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR <EMAIL@ADDRESS>, 2025. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "POT-Creation-Date: 2025-08-18 10:12+0100\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.17.0\n" ``` However, if I instead run: ```bash pybabel extract -F babel.cfg -o template.pot -k _ -k _l -k _n:1,2 -k _nl:1,2 -k _p:1c,2 -k _pl:1c,2 -k _np:1c,2,3 -k _npl:1c,2,3 app/data/PaymentMethods.py ``` I get the translatable strings extracted in `template.pot`: ``` # Translations template for PROJECT. # Copyright (C) 2025 ORGANIZATION # This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR <EMAIL@ADDRESS>, 2025. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" "POT-Creation-Date: 2025-08-18 10:13+0100\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.17.0\n" #: app/data/PaymentMethods.py:6 msgid "Cash" msgstr "" #: app/data/PaymentMethods.py:7 msgid "Card" msgstr "" #: app/data/PaymentMethods.py:8 msgid "Cheque" msgstr "" #: app/data/PaymentMethods.py:9 msgid "Direct Debit" msgstr "" #: app/data/PaymentMethods.py:10 msgid "Bank Transfer" msgstr "" ``` Am I doing something wrong, or is there a bug here? I've done my best to make this a small and reproducible test case. Thanks :pray:
2 条评论