Friday, October 14, 2011

Notes of Internationalization (I18N) in Python

How to run xgettext, msgfmt and msguniq on Windows
  • GNU tools xgettext, msgfmt and msguniq are usually used together to extract translatable messages from source codes. They are also used in Python or Django, and shipped with most popular Linux distributions like Ubuntu. 
  • On Windows, you can install GnuWin32or MinGW, and add the 'xxx\bin' into the system PATH. Note, if you only add it to your user PATH, it will fails to be called by Django.
Add system language setting
  • On Windows, you need to add a system-wide environment variable LANG=en_US, if it's not there yet.
  • On Linux, the environment variable LANG may already be there, looks like en_US, or en_US.utf8. You can check this by shell command: "echo $LANG". However, apache on Linux is likely overwriting this setting to something else. If this is the case, please make a change to /etc/apache2/envvars (if apache is installed there) as the following: "export LANG=xxx" => "export LANG=en_US", where xxx possibly is C.
Change Python's default encoding
  • Python's default encoding is ASCII, which needs to be changed to UTF-8. We can change this setting in, which is automatically loaded every time python starts. 
  • Make sure that there is a in your PYTHONPATH, otherwise create one. Add following codes to it:
import sys

No comments:

Post a Comment