Django localization language file

Source: Internet
Author: User
Tags i18n

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.