Pygettext.py and msgfmt.py on Mac OS X

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

Is the pre-installed version of Python for Mac OS X 10.7 the lack of these tools, and if so, how can I get them?

Thanks.

+7
source share
5 answers

Both of these scripts are in the catalog of various Python source tools. This directory is often not part of the binary installation of Python, such as those provided by Apple on OS X. However, they are easy to download separately from the original version of Python; see the latest releases here . For the current version of Python 2.7.3, you can 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* 

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

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

With python 3 and MacOS> = 10.9, installing gettext via homebrew will not link libraries, and this will result in a Can't find msgfmt error.

It helps:

 $ brew install gettext # if not already done $ brew link gettext --force 

Thanks to fooobar.com/questions/258403 / ...

+11
source

If you correctly installed Python on Linux, you can access the binary versions from the command line. So, to create a .pot file, you can enter:

  $> pygettext [options] source_file_list 

I found that I have two versions of pygettext: one for version 2.7 and the other for 3.2, but they seem to work almost the same. To create .mo files from .po files:

  $> msgfmt [options] file.po 

but you need to make sure that you are not accidentally using the gnu version. The msgfmt version in Python is much simpler. Both teams have help, so you can check the parameters (and versions) with:

  $> pygettext --help 

and

  $> msgfmt --help 

If in doubt, loading a Python source as suggested above is a belt and snapping approach.

I still find my way around me, so if someone knows better, add your comments :)

0
source

create a symbolic link

 sudo ln -s /Library/Frameworks/Python.framework/Versions/3.7/share/doc/python3.7/examples/Tools/i18n/pygettext.py /usr/local/bin/pygettext 
0
source

Using find. -name pygettext.py/msgfmt.py find. -name pygettext.py/msgfmt.py find. -name pygettext.py/msgfmt.py find. -name pygettext.py/msgfmt.py , I cannot find these two files on macOS, there is no data in the system Python installation ( /System/Library/Frameworks/Python.framework/Versions ) or in the Anaconda Python distribution.

But we can always directly download these two files from the Python source code. They are currently located at : https://github.com/python/cpython/tree/master/Tools/i18n.


In addition, pygettext.py and msgfmt.py are imitators of the GNU gettext toolset: xgettext and msgfmt . You can also check if these GNU toolkits have already been installed. ( type -a xgettext/msgfmt )

If not, you can install it using the port MacPort command or the Anaconda conda .

 port install gettext conda install gettext 
0
source

Source: https://habr.com/ru/post/920333/


All Articles