I have followed this post on how to create a .pot file in PoEdit: https://wordpress.stackexchange.com/questions/149212/how-to-create-pot-files-with-poedit. Everything worked as the user has stated, except for the saving as a .pot file. The program did not allow saving as .pot file and saved as .po instead. Other posts suggested changing .po to .pot manually because it is supposedly the same thing. I did this and followed this very detailed tutorial on using gettext: https://inventwithpython.com/blog/2014/12/20/translate-your-python-3-program-with-the-gettext-module/.

The post suggests creating the .pot file with the same name as your .py file and putting the translations (.po in .mo files) in ./locale/es/LC_MESSAGES/ (locale, es and LC_MESSAGES are manually created folders).

As stated in the post, the following code:

import gettext
es = gettext.translation('main', localedir='locale', languages=['es'])

should find that file and translate from English to Spanish.

However, mine does not. I get this message saying file was not found:

FileNotFoundError: [Errno 2] No translation file found for domain: ‘main’

I did everything the same way the post suggested except for the name of my python file, which is main.py not guess.py (the post was about a guess game).

I have tried repeating the process of creating the .po file and the translation for 3 times but get the same result each time. What could be wrong or what else could I try?

Read more here: Translation file (.pot) not found with gettext


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: