I try to make a multilingual application with pygettext. I reproduce the steps described here: https://phrase.com/blog/posts/translate-python-gnu-gettext/.
The translatable strings should appear at the bottom of the .pot file:
#: src/main.py:5
msgid "Hello world"
msgstr ""
#: src/main.py:6
msgid "This is a translatable string"
msgstr ""
The problem is that in my case there msgid are empty, though .pot file is created.
It looks like pygettext just doesn't see them in the code.
That's how my whole .pot file looks like:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION
"
"POT-Creation-Date: 2021-01-16 13:50+0300
"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>
"
"Language-Team: LANGUAGE <[email protected]>
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=cp1251
"
"Content-Transfer-Encoding: 8bit
"
"Generated-By: pygettext.py 1.5
"
My python code:
# main.py
import gettext
_ = gettext.gettext
def print_some_strings():
print(_("Hello world"))
print(_("This is a translatable string"))
if __name__ == '__main__':
print_some_strings()
Project structure:
pdf_invoices
│ └── en
│ └── LC_MESSAGES
│ └── base.pot
└──__main__.py
Command creating .pot file:
C:>C:UserseloseAnaconda3Toolsi18npygettext.py
-d C:UserselosePycharmProjectspdf_invoices\__main__.py
-o C:UserselosePycharmProjectspdf_invoiceslocales
uase.pot
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…