Development Book V17: Gettext Tools

The GNU gettext tools play a crucial role in creating, employing, and maintaining translation files. Odoo employs gettext methods like, underscore function _() to facilitate accelerated translations. This method allows developers to annotate string literals in the code that need translation within the context of the current language. Importing _ from the Odoo packages is necessary to utilize this approach in Python code.

odoo-development

Once it is imported, we can write the string literals within _(), which will include them in the translation file.

odoo-development

Export the translation of the language for the corresponding module.

odoo-development

The string literal intended for translation is observable in the PO file, with the untranslated string provided under msgid. The translated string for the respective language can be added in msgstr.

odoo-development

After adding the translations we can incorporate this with the module in two ways.One of them is importing the translated file.

odoo-development

Another method is adding the translation files within the i18n directory of the module and translations will be automatically updated.This practice is very beneficial when releasing apps or modules supporting multiple languages. The translation file is named using the ISO code of the language in Odoo (e.g. fr_CA.po). The translation template from Odoo is also added to the directory with the file name as module name(e.g. base.pot).

odoo-development

The translations will be added to the modules and will be loaded automatically on activating the languages.

whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message