Okay, let’s go step by step.
On my Windows 11, 64 bit, English locale, Python 3.10, PyCharm machine.
Here is a sample script:
import gettext
from pathlib import Path
from gettext import gettext as _
gettext.translation(
"translate",
localedir=Path(__file__).resolve() / "locale",
languages="ru",
fallback=True,
).install()
print(_("Near the seaside, the oak is green"))
The path to the script is:
C:\Users\vladi\AppData\Roaming\JetBrains\PyCharmCE2022.2\scratches\scratch_38.py
:
To create .pot
file, I run this command in the command line:
python C:\Users\vladi\AppData\Local\Programs\Python\Python310\Tools\i18n\pygettext.py -d translate C:\Users\vladi\AppData\Roaming\JetBrains\PyCharmCE2022.2\scratches\scratch_38.py
Then, I open translate.pot
in Poedit, and make the following configuration:
Source text Near the seaside, the oak is green
→ translation У лукоморья дуб зелёный
I save translate.mo
and translate.mo
files in the following newly made directory: C:\Users\vladi\AppData\Roaming\JetBrains\PyCharmCE2022.2\scratches\locale\ru\LC_MESSAGES
:
translate.po
reads as follows:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2022-11-08 09:29+0100\n"
"PO-Revision-Date: 2022-11-08 09:31+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n"
"Generated-By: pygettext.py 1.5\n"
"X-Generator: Poedit 3.2\n"
#: C:\Users\vladi\AppData\Roaming\JetBrains\PyCharmCE2022.2\scratches\scratch_38.py:12
msgid "Near the seaside, the oak is green"
msgstr "У лукоморья дуб зелёный"
I run the file, and still, I do not receive the Russian translation:
What am I doing wrong?