cstrap
11/24/2015 - 10:30 AM

A way to generate localization files :: Python

A way to generate localization files :: Python

# Creating Template 
$ find . -iname "*.py" -exec xgettext -o messages.pot {} \;

# Copy template message.pot into locale/XX/LC_MESSAGES
# For example (this is a typical django app tree structure) 
...
│   ├── locale
│   │   ├── en
│   │   │   └── LC_MESSAGES
│   │   │       ├── django.mo
│   │   │       └── django.po
│   │   └── it
│   │       └── LC_MESSAGES
│   │           ├── django.mo
│   │           └── django.po

$ cp message.pot locale/en/LCMESSAGES/django.po

# Edit the django.po file with an editor
$ vi django.mo

# Compiling .mo file
$ msgfmt -o django.mo django.po

# Resources
# https://pymotw.com/2/gettext/
# http://stackoverflow.com/questions/739314/easiest-way-to-generate-localization-files