Chapter 8 - Odoo 15 Development Book

Gettext Tools

The GNU gettext tools help in producing, using, and updating the translation files. Odoo uses the gettext-like method ‘underscore’ _() for speeding up the translations. In the code, we can use it to mark the string literals, those to be translated, with the language in the current context. We have to import the _ from odoo packages to use it in the python code.

odoo-development-book

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

odoo-development-book

Now, export the translation file(PO file) for a language for the corresponding module.

odoo-development-book

We can see that the string literal to be translated is available in the PO file. The untranslated string will be given in the msgid. We can add the translated string for the corresponding language in msgstr.

odoo-development-book

Once we complete adding/ updating the translations, we can add them to Odoo in 2 ways. We can import the translation file manually to add/ update the translations in Odoo.

odoo-development-book

If we need to update the translations automatically with the module, create a new directory i18n inside the module and add our translation files to it. This is very useful when we release the apps/ modules that support multiple languages. The file name for the translation files will be 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. point_of_sale.pot).

odoo-development-book

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

whatsapp_icon
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