Chapter XV: internationalization and localization -gettext: Message catalog - Conversion Workflow Overview

Chapter 15: Internationalization and Localization

15.1 gettext: The message catalog
gettext module provides a pure Python implementation, compatible with the GNU gettext library for completion message conversion and catalog management. Python source code using tools provided by the release, can be extracted from a set of source files in the message, constructs a message containing a catalog of conversion, and use this message to the user at runtime catalog display an appropriate message. Message catalogs may be used to provide international program interface, using a suitable message displayed to the user's language. Other messages can also be customized in English, including different packaging or Partner Interface "skinning."
Description: Although the documentation states Python standard library already contains all the necessary tools, but even provides the appropriate command-line options, pygettext.py can not extract the package the message in ngettext call. These examples use xgettext GNU gettext toolset, rather than pygettext.py .

15.1.1 conversion workflow overview
establishment and use of the conversion process involves five steps.
1. identify and tag source code contains literal string to be converted message.
First identifies the message in the program source code to be converted, and the literal string tag, so as to extract the program finds the literal strings.
2. extracting message
after the code string identification source may be converted, using xgettext extracted the strings, and create a .pot file, or template conversion (translation template). This template is a text file that contains a copy of all the identified strings and convert the corresponding placeholders.
3. The conversion messages.
.Pot file a copy provided to the converter, the extension to .po. This file is an editable .po source file is used as input to the next compiled. To update the file converters in the header text to translate all the strings.
4. cataloged by the transformation "compile" message.
When the converter back to full .po file, use, msgfmt this text file is compiled into a binary catalog format. Runtime catalog lookup code will use the binary format.
Load and start the appropriate message catalog 5. runtime.
The final step is to increase the application of a few lines of code, and loading the configuration message catalogs, and install the conversion function. In this regard there are several methods have advantages and disadvantages.

Guess you like

Origin blog.csdn.net/weixin_43193719/article/details/94749742