It is important to consider translations when we perform customizations in odoo. In this blog let us see how to add the translation for custom module and also the implicit and explicit exports in odoo13. In the module structure you can see a folder i18n which is used to add translation to your modules.
The i18n module consists of .po files. These .po files can be obtained by exporting the custom module. Let’s see how to perform this:
Activate Developer Mode Go to Settings -> Translation -> Export Translation.
Choose the custom module name of which you want to add translation.
Now Go to Settings -> Translation -> Export Translation
1. Select the required custom module.
2. Export your custom module select the file format as po format.
3. Choose the required language
Move the po file to the i18n folder of your custom module.
Place the translation as follows in .po file
msgid ”custom text to be translated”
msgstr “translation for the string/text”
You can also see the translated terms and status using Translated Terms
Implicit Exports
Odoo translates the default strings other than custom strings. In Qweb views, the translation for field can be restricted using t-translation="off"
The content included inside this block will not undergo translation. The block can be defined as shown below:
<t t-translation="off">
<!-- qweb fragments -->
</t>
In the case of models the translation can be restricted using the attribute _translate=False via python code.
Example:
Class ModelName(models.Model):
_name = 'new.model.name'
_description = 'Model Description'
_translate = False
Unless the _translate = False is given the strings, help,_sql_constraints,_constraints and all other values are translated.
Explicit Exports
In case of explicit exports the strings should be marked explicitly for export/translation using wrapping functions.
In Python the wrapping function used is odoo._() :
raise UserError (_("Raise Error"))
In Javascript the wrapping function is _t()
var title = _t("This date is on the future.");
There are certain Do’s and Don'ts to be considered while performing translations:
In case of variables specify the variable name after translation lookup:
1. raise UserError(_("Unrecognized field %s .") % field_name)
2. Do not split the translation in multiple lines and also do not use unwanted trailing spaces
3. Do not use plural words for translation as they may vary with languages