Odoo 16 Development Book

Gettext Tools

The GNU gettext tools help produce, use, and update the translation files. To expedite translations, Odoo employs the gettext-like method "underscore" (). We can use it to designate string literals in the code that need to be translated with the language that is appropriate for the situation. To use it in the Python code, we must import it from the Odoo packages.

odoo Development

The string literals can be written within _() after we import it because doing so will include them in the translation file.

odoo Development

Export the translation file (PO file) for the relevant module for that language now.

odoo Development

We can see that the PO file contains the string literal that needs to be translated. The msgid will contain the untranslated string. The translated string for the relevant language can be added to msgstr.

odoo Development

Once the translations have been added or updated, there are two ways to add them to Odoo. To add or change translations in Odoo.

odoo Development

Create a new directory called "i18n" inside the module and place our translation files there if we need to update the translations automatically with the module. This is quite helpful when we release apps or modules that support several languages. The ISO code for the language in Odoo will be used as the filename for the translation files (for example, fr CA.po). The directory also contains the Odoo translation template, which is added with the filename serving as the module name (for example, point of sale.pot).

odoo Development

When the languages are activated, Odoo will automatically load the translations that were added with the modules.

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