This article only describes the language file section in Django.
1. How to Create a language file?
UseDjango-admin.py The makemessages command automatically creates a language file, which is a plain text file suffixed with. Po.
The format of language file is:
Msgid "Welcome to my site ."
Msgstr "welcome"
Msgid is the string to be converted and exists inProgramSource code, so do not change
MsgstrIs an explanation of msgid based on a specific language. It is null at first, and developers need to make corresponding changes to msgstr
2. Compile the message file.
After creating the language file, compile the language file into a more effective format. You can useDjango-admin.py compilemessages.
When you use the preceding two commands, pay special attention to them in a Windows environment because these two commands use a component that is not installed by default in Windows,Gettext. To run in Windows, you need to download and install gettext. The download and configuration methods are as follows:
1. InHttp://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/downloadGettext-runtime-X.zip andThe latest version of the gettext-tools-X.zip (Note: X is the version number)
2. ReplaceDecompress the bin \ directory and put it in the same folder, for exampleC: \ Program Files \ gettext-utils
3. Set the system environment variables and add them to the system environment variables.; C: \ Program Files \ gettext-utils \ bin (the specific path depends on the gettext installation path)
The storage structure of Django language file is as follows:
Mysite/
Locale/
Zh/
Lc_messages/
Django. Po
Django.mo
Note: For more information about localization, see Django docs, http://docs.djangoproject.com/en/dev/topics/i18n/localization/#topics-i18n-localization