1. Translating messages#
1.1. How it works#
The support of messages in multiple languages is based on the standard gettext tools.
Here is an overview of how gettext works. Refer to the documentation for this product for more details.
Error messages are collected in catalogs (confer [D4.06.01]).
The i18n.py module (from the Execution package) is in charge of choosing the display language and « installing » the message conversion function (this is the « _ » function).
The language chosen by default depends on the execution environment: environment variables LANG, LANGUAGE, etc. (refer to the gettext documentation for the order of priority and the various variables). The same variable is used to determine how to display non-ascii characters, especially accented characters. This is the utf-8 or iso-8859-1 encoding).
The user can force the choice of language in command DEBUT (confer [U4.11.01]).
It is this module that defines the*domain* gettext and therefore the name of the file in which the translated messages will be searched. We use aster_ + the name of the version, for example: aster_stable for the operating version, aster_testing for the stabilized development version.
Gettext tools (pygettext in this case) allow you to extract messages from source code files in order to produce a POT file, for example: aster_unstable.pot.
For each language, a copy of this file is created along with the translations of the messages, called PO files, for example: aster_unstable.en.po.
These PO files are « compiled » in order to produce so-called MO files that contain the messages, their translations and a hash table to access them. These MO files are used when Code_Aster is executed. They are installed in $ ASTER_ROOT /share/locale/, in a subdirectory dedicated to each language, for example: en/ LC_MESSAGES /aster_unstable.mo.
For testing purposes essentially, you can choose a different directory by setting the environment variable ASTER_LOCALEDIR instead of $ ASTER_ROOT /share/locale/.
During execution, when a message must be displayed, the « _ » function is called with the string of the original message as argument (the one who writes in the source code, in the message catalog in general). If this message is present identical in the MO file, then the « _ » function returns the message as it was translated (in the message printing mechanism, this text is then formatted, supplemented with variables if necessary before being displayed).
If the MO file is not found or if the message is not found, the original message is displayed regardless of the language chosen (so in French).
If a message is modified in the source code, even just one character, it is necessary that the PO and MO files be regenerated otherwise the translation will not be displayed.
1.2. Organization#
PO files cannot be managed in sync with the source code. There is necessarily a time lag between the rendering of the message in French and the updating of the translation (at least as long as developers are not required to simultaneously translate their messages into all supported languages).
Moreover, in open source projects, different teams often manage translations.
A source repository has been created at
`https://bitbucket.org/code_aster/codeaster-i18n`_ < https://bitbucket.org/code_aster/codeaster-i18n>.
It allows you to broadcast the latest available versions of POT and PO files (for English at first).
Today, the repository is managed by the person responsible for this feature. Tomorrow it can be transferred to an external team that will want to invest in it. Contributors can*clone* this repository, then suggest to the main repository administrator to retrieve and include their contributions (pull request).
The objective is to offer translations as complete as possible for the stable and testing versions, in order to provide and install them in the Code_Aster packages, each time they are stabilized.
The translation of the unstable version is by nature constantly under construction due to the great volatility of the messages each week.