I’m building a Python application that utilizes a bunch of translated strings. The directory structure housing said strings looks like this:
/locales
default.pot # reference English strings live here
/es_ES
/LC_MESSAGES
default.po #Spanish strings
/de_DE
/LC_MESSAGES
default.po #German strings
These default.po files were generated by a PHP application, but as far as I know, they conform to the general standard needed to work with gettext implementations.
When I attempt to utilize these strings in Python using gettext, the following goes down (this example was run from within the locales directory:
>>> import os; os.listdir('.')
['.svn', 'de_DE', 'default.pot', 'eng', 'es_ES', 'fr_FR', 'ja_JP', 'ko_KR', 'pl_PL', 'pt_BR', 'ru_RU']
>>> import os.path
>>> os.path.exists('./es_ES/LC_MESSAGES/default.po')
True
>>> import gettext
>>> ldir = 'es_ES/LC_MESSAGES/'
>>> t = gettext.translation('default',ldir)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 469, in translation
IOError: [Errno 2] No translation file found for domain: 'default'
>>>
I’m not sure what I’m doing wrong here (beyond inexperience with this library and the notion of ‘domain’ in its context).
Am I making a simple mistake? Or do I have a fundamental flaw in my understanding of how this crap works?
Thanks!
I’m very rusty on this, but based on past experience and http://docs.python.org/library/gettext, I can see two main things missing here:
A quick example: