Skip to content

How to add and edit translations in Odoo

One of the most convenient features of Odoo is its translation system.

Odoo can detect strings from various sources like field definitions, XML views, and even Python code if properly enclosed with the special underscore tool: _('Your String').

This means that almost any text that you see on the user interface can be edited and translated.

Once a module is installed or upgraded, Odoo detects new strings and adds them as records to its ir.translation database model.

Translations are identified by their original source value, translation value, module, model, and field name. For translations embedded in Python code, the file location is also taken into account.

There are two ways to edit translations in Odoo: using the frontend or via a custom module.

Frontend

Translations can be accessed by enabling debug mode either through Settings > General Settings > Activate the developer mode or by simply adding ?debug=1 to the URL.

This enables the Translations menu in the Settings module.

Translated Terms shows you the list of all translations in the database:

Here, you can easily update or add new translations.

However, remember that these changes are just in the current database and will not be kept in new databases or if you regenerate the translations.

Another important item within the Translations menu is Export Translation.

This allows you to quickly export all the detected strings for a particular language and is a great starting point to translate a new module or language.

If you select the PO file format, Odoo will give you a ready-made template to start your translation.

More info about the PO file format: https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html

Custom Module

A more stable approach for adding or editing translations is creating a new module.

You need a basic __manifest__.py to describe your module.

The sequence key determines the order in which your module is loaded. It defaults to 100 and you can change it to make Odoo choose your translation over others.

{ "name": "Your Translation Module", "version": "13.0.1.0.0", "category": "Localization", "summary": "About your module...", "author": "Mohammad Tomaraei", "website": "https://tomaraei.com", "license": "AGPL-3", "depends": ["base"], "installable": True, "application": False, "auto_install": True, "sequence": 101 }
Code language: Python (python)

Next, create a folder named i18n your module’s main directory.

Within this folder, you can add .po files corresponding to translations for various languages. It follows the same format as in the exported PO file above.

For example, a Hungarian translation would need the i18n/hu.po file.

To activate your translation:

  1. Restart the Odoo server
  2. Install or upgrade your module
  3. Go to Settings > Translations, and click Generate Missing Terms

If you happen to get a CardinalityError, it’s because you have the same original value / translated value combination twice and a database constraint prevents you from adding the same record twice.

Published inOdoo