In Odoo, translations must be done according to each user's language. In some cases, we need to translate fields, labels, and strings depending on the user's language.
In this blog, we will discuss how to add language translation to a custom module in Odoo 16 and how to add a new language in Odoo.
Settings>Translation>Languages
Here, we have many languages. First, we need to enable a new language other than English. Here I am activating the Arabic(Syria)language.
And then, we have to export the translation for our custom module.
Clicking on the export translation menu, we have a pop-up window.
First, we can select the language, and the file format is po file, and then we have to add our custom module. Here we have a custom module,“Estate”.
After completing all fields in the export settings, we can click on the button Export.
Here we can save the PO file in our local, and then we can just copy the downloaded PO file into the pycharm custom addons. We need to create a new directory inside the custom add-ons folder and add the downloaded PO file to the directory.
Inside the downloaded PO file, we can do the required translations for each entity here.
#.module:estate
#:model:ir.ui.menu,name:estate.estate_first_level_menu
msgid "Advertisement"
msgstr ""
#.module:estate
#:model:ir.model.fields,field_description:estate.field_estate_property__bedrooms
msgid "Bedrooms"
msgstr ""
#.module:estate
#:model_terms:ir.ui.view,arch_db:estate.estate_property_view_tree
msgid "Channel"
msgstr ""
The msg_id will be the English version of the translated version corresponding to the specific language. You can choose here, and we can also manually add the corresponding translated words. Because this is a custom module, here I just translated the above.
Here you can see the menu Advertisement is converted into the corresponding Arabic version, and also the field Bedrooms is converted into the corresponding Arabic version. Then upgraded the custom module, but we can't see any changes because the current language for the administrator is English.
So we need to change it to Arabic.
Then we can open our module where we can see the field bedrooms and the menu advertisement is changed to the corresponding Arabic name.
Import Translations In Odoo 16
Navigating to Settings > Import/Export > Import Translation will bring up the import translation wizard, where you can import the translations.
By clicking on the import translations menu, it will open up a wizard, as shown below,
Add a language name, add a language code, and upload the PO/translation file that will be imported, which are all selectable in the translation wizard. The file types that are supported are.csv,.po, and.pot.
We can choose to overrule phrases that have already been translated by using the "Override Existing Terms'' button. The PO file is also editable, downloadable, and deletable. When finished, import the translations into Odoo by clicking the "Import" button.
Seeing The Translated Text
You can click on the translation icon that is shown in the Odoo field to view the translated content there. I'm thinking of a sample of Odoo merchandise.
You can see the translated product name and view all other installed translations in the popup.
This is how we can define translations in Odoo 16. Then we can see How To Add New Languages To Odoo 16.
To Include A New Language to Languages
To include a new language to languages in Odoo, we have to create a.csv file named ‘res.lang.csv’ under the data directory.
The res.lang.csv file contains the following.
"id","name","code","iso_code","direction","grouping","decimal_point","thousands_sep","date_format","time_format","week_start"
"base.lang_isk","Icelandic / íslenska","is","is","Left-to-Right","[]",",",,"%d-%m-%Y","%H:%M:%S","7"
This is all about how to add a new language to Odoo 16 and how to define translation to a custom Module.
To read more about configuring translation to custom module & add a new language in Odoo 17, refer to our blog How to Configure Translation to Custom Module & Add a New Language in Odoo 17