Enable Dark Mode!
how-to-add-translation-to-the-custom-module-in-odoo-15.jpg
By: Mily Shajan

How to Add Translation to the Custom Module in Odoo 15

Technical Odoo 15

In Odoo, Translations need to be done based on each user’s language. In some cases, we need to translate the field, labels, and strings based on the user’s language. This blog discusses how to add translation to custom modules in Odoo 15. While going through the module structure of Odoo 15, we can see a folder i18n which helps the translation.

how-to-add-translation-to-the-custom-module-in-odoo-15-cybrosys

i18n folder contains the translation of modules in different languages. Which stands for internationalization. It contains two types of files 

- .po files

- .pot files

.po files are simple text files where we can add translation packages when new languages are added.

.po have .pot files, which are the templates of it.

The translation is performed through the administration interface when it is in debug mode

User can switch the language of the interface using 

Settings > Translations > Languages.

From here, users can choose the language and Activate and Translate it. Which changes the whole interface to that language.

Export Translation

For Translation, Initially the user has to export those translated files from the custom module and then download the same.

Settings > Translations > Export Translation

how-to-add-translation-to-the-custom-module-in-odoo-15-cybrosys

a) Choose the language for translation

b) Select the file format

c) Select the module that wants to translate

And export it, giving the exported translation file in.po format. The file was generated using UNIVERSAL/UTF -8 encoding.

Then download that .po file and add it inside the i18n folder, which helps for internationalization in our custom module.

#. module: tips_and_tricks
#: model:ir.model.fields,field_description:tips_and_tricks.field_tips_tricks__upper_name
msgid "UPPER NAME"
msgstr "nombre superior"
#. module: tips_and_tricks
#: model:ir.model.fields.selection,name:tips_and_tricks.selection__res_partner__marital_status__unmarried
msgid "Unmarried"
msgstr "soltera"

This is an example of a .po file for translation,

Module: It specifies the module 

Model: It gives  model as ir.model

Field_description: It shows the module_name.field_name

Msgid: At here it gives the Label name of the field

Msgstr: At here we can add the translated name of the field

So here in the msgid it has the field name “UPPER NAME” and its translation in Spanish is updated in msgstr. In the msgstr user can add the translation of that word, if the entered translation is not in the proper language field doesn’t get translated.

And then switch the language of the user here it as Spanish from my profile menu of the user, and then update the custom module. Then field gets translated as follows

how-to-add-translation-to-the-custom-module-in-odoo-15-cybrosys

Also, we can check the translated words and their status from the administration interface in debug mode

Settings > Translations > Translated Terms,

Which gives a tree view showing the translated field and its language, module, type, and its status of Translation. And helps us to check if the field or menu name is translated or not.

Also, we can do the translations using the Import Translation tool

Settings > Translations > Import Translation

how-to-add-translation-to-the-custom-module-in-odoo-15-cybrosys

Implicit Records

In Odoo; it automatically translates the default strings. The Translation can be blocked using  

t - translation=”off”

<t t-translation="off">

The data inside this <t>  tag will not undergo translation.

Also, we can block this translation within the model also by _tranlsate=False, to a model

class ConverterTest(models.Model):
   _name = 'web_editor.converter.test'
   _description = 'Web Editor Converter Test'
   _translate = False

_translate = False, Which also helps to restrict the translation within a python code inside the model. When an attribute _translate = False is given for a model.

For the translation of sql_constrains,_constrains, help we can also use this _translate = False.

For the fields, translation can be done as follow.

name = fields.Char('Follow-Up Action', required=True, translate=True)

We can add it for each field that we like to be translatable.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 
whatsapp
location

Calicut

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

location

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

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