Translating Module

Exporting translatable term

Translations export is performed via the administration interface by logging into the backend interface and opening SettingsTranslationsImport / ExportExport Translations

 

A number of terms in your modules are “implicitly translatable” as a result, even if you haven’t done any specific work towards translation you can export your module’s translatable terms and may find content to work with.

Translations export is performed via the administration interface by logging into the backend interface and opening Settings ‣ Translations ‣ Import / Export ‣ Export Translations

  • leave the language to the default (new language/empty template)
  • select the PO File format
  • select your module
  • click Export and download the file

 

This gives you a file called yourmodule.pot which should be moved to the yourmodule/i18n/ directory. The file is a PO Template which simply lists translatable strings and from which actual translations (PO files) can be created. PO files can be created using msginit, with a dedicated translation tool like POEdit or by simply copying the template to a new file called language.po. Translation files should be put in yourmodule/i18n/, next to yourmodule.pot, and will be automatically loaded by Odoo when the corresponding language is installed (via Settings ‣ Translations ‣ Languages)

Implicit exports

Odoo automatically exports translatable strings from “data”-type content:

  • in non-QWeb views, all text nodes are exported as well as the content of the stringhelpsumconfirm and placeholder attributes
  • QWeb templates (both server-side and client-side), all text nodes are exported except inside t-translation="off" blocks, the content of the titlealtlabel and placeholder attributes are also exported
  • for Field, unless their model is marked with _translate = False:
    • their string and help attributes are exported
    • if selection is present and a list (or tuple), it’s exported
    • if their translate attribute is set to True, all of their existing values (across all records) are exported
  • help/error messages of _constraints and _sql_constraints are exported

Explicit exports

When it comes to more “imperative” situations in Python code or Javascript code, Odoo cannot automatically export translatable terms so they must be marked explicitly for export. This is done by wrapping a literal string in a function call.

In Python, the wrapping function is odoo._():

title = _("Bank Accounts")

In JavaScript, the wrapping function is generally odoo.web._t():

title = _t("Bank Accounts");

The lazy version of _ and _t is odoo._lt() in python and odoo.web._lt() in javascript. The translation lookup is executed only at rendering and can be used to declare translatable properties in class methods of global variables. 

Variables

Don’t the extract may work but it will not translate the text correctly:

_("Scheduled meeting with %s" % invitee.name)

Do set the dynamic variables as a parameter of the translation lookup (this will fallback on source in case of missing placeholder in the translation):

_("Scheduled meeting with %s", invitee.name)

Blocks

Don’t split your translation in several blocks or multiples lines:

# bad, trailing spaces, blocks out of context
_("You have ") + len(invoices) + _(" invoices waiting")
_t("You have ") + invoices.length + _t(" invoices waiting");

# bad, multiple small translations
_("Reference of the document that generated ") + \
_("this sales order request.")


Leave a Reply

Your email address will not be published.