Search code examples
pythonmacoslocalizationgettext

pygettext.py and msgfmt.py on Mac OS X


I want to translate strings in my Python app on my Mac OS X 10.7. I can import the gettext module but i can't find the tools pygettext.py and msgfmt.py, which according to the Python docs should be somewhere in my Python installation.

Is the pre-installed Python version on Mac OS X 10.7 missing these tools and if yes, how can I get them?

Thanks.


Solution

  • Both of those scripts reside in the miscellaneous Tools directory of the Python source. This directory is often not included in a binary installation of Python such as the ones supplied by Apple in OS X. However, it is easy to download them separately from a Python source release; see the most recent releases here. For the current Python 2.7.3 release, you could do the following:

    $ curl -O http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
    $ tar -xf Python-2.7.3.tgz 
    $ cd Python-2.7.3
    $ cd Tools/i18n/
    $ ls
    makelocalealias.py  msgfmt.py*          pygettext.py*
    

    Beginning with Python 3.2, the Tools directory is installed by python.org OS X binary installers. You'll find it inside the Python framework at:

    /Library/Frameworks/Python.framework/Versions/3.2/share/doc/python3.2/examples/Tools