Translation file (.pot) not found with gettext

I have followed this post on how to create a .pot file in 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:

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 not (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

Leave a Reply

Your email address will not be published. Required fields are marked *