Setting Language Preferences for Data Retrieval and Loading with Odoo

Upcoming release 24.0 and BETA release 23.1.219 and later have functionality to set the language code for translateable elements.

To query the list of installed user interface languages, the following query can be used:

--
-- List of installed user interface languages.
--
select code
,      display_name
from   lang@odoo

Query Odoo in the Default Language

The default output can be queried easily using:

--
-- Disable caches.
--
set use-http-disk-cache@odoo false

set use-http-memory-cache@odoo false

--
-- Choose default language.
--
set context-language@odoop ""

select code
,      name
from   account.account@odoo
where  code in ('EOL0100', 'EOL0110')
and    company_id = 7

which results for instance in:

Code Description
EOL0100 Inventory
EOL0110 Bedrijfsinventaris

when the account EOL0100 is defined as:

Note that account EOL0110 has a Dutch translation by default, since Odoo copied the Dutch text specified as default text to all translations.

Switch Language on the Odoo APIs

When you want to retrieve the French names of the accounts, the language can be set using set context-language and a language from the list above, as illustrated below:

--
-- French
--
set context-language@odoo "fr_FR"

select code
,      name
from   account.account@odoo
where  1=1
and    code in ('EOL0100', 'EOL0110')
and    company_id = 7

The result has translations for the name where available:

Code Description
EOL0100 Inventaire de l’entreprise
EOL0110 Bedrijfsinventaris

Note that “Bedrijfsinventaris” is not in French. Actually, this Odoo-environment has a Dutch translation listed in the Odoo-user interface for this specific account.

Choosing Languages

In case the installed languages are unknown, providing an invalid language code will raise an error listing the installed languages:

set context-language@odoo "xx"

with error:

Language ‘xx’ is not installed in your Odoo database.
Install the language ‘xx’ in Odoo or choose an already installed language from ar_001, cs_CZ, da_DK, de_DE, en_US, es_ES, fi_FI, fr_FR, it_IT, ja_JP, ko_KR, nb_NO, nl_NL, pl_PL, pt_PT, sv_SE.

Retrieve Translations Everywhere in Odoo

For translation purposes, such as integration with Amazon Translate, DeepL, Google Translate or CAT-tools such as Localazy or OmegaT, the data can be retrieved en mass.

First search for the translateable fields in Odoo using the query:

select mfd.model
,      mfd.name
from   ir.model_fields@odoo mfd
where  mfd.translate = true
and    mfd.model = 'product.product'

In this case, the search for translateable content was restricted to products. The result is:

image

The translations of all products can be retrieved using odoo.model.translations as in:

select pdt.id
,      tln.*
from   product.product@odoo pdt
join   odoo.model.translations@odoo
       ( 'product.product'
       , 'description'
       , pdt.id
       ) tln

with result similar to:

image

This is quite slow, retrieving approximately 20 translations per second.

Update Translations

Individual translations can be updated in several ways. The easiest way is to change the language to the intended language and update the translation, such as:

set use-http-disk-cache@odoo false

set use-http-memory-cache@odoo false

--
-- Get original Dutch labels for name.
--
set context-language@odoo "nl_NL"

select code
,      name
from   account.account@odoo
where  code = 'EOL0120'
and    company_id = 7

--
-- Update French only.
--
set context-language@odoo "fr_FR"

select code
,      name
from   account.account@odoo
where  code = 'EOL0120'
and    company_id = 7

update account.account@odoo
set    name = 'Frais d''établissement'
where  code = 'EOL0120'
and    company_id = 7

--
-- Update English only.
--
set context-language@odoo "en_US"

select code
,      name
from   account.account@odoo
where  code = 'EOL0120'
and    company_id = 7

update account.account@odoo
set    name = 'Formation costs'
where  code = 'EOL0120'
and    company_id = 7

The translateable columns are loaded into the language specified using context-language while loading data with insert or bulk insert.

Update All Translations of a Specific Column of a Row

Each language requires a separate API-call per combination of row and language to update the translateable fields. This can become slow when several languages are installed. Odoo also offers the possibility to update all translations of a column on a specific row. For this purpose, Invantive UniversalSQL offers the procedure update_translations in the driver-specific package odoo.

For each language installed, the procedure is extended by a parameter that can be addressed using it’s name as shown below for the product with ID 472:

begin
  odoo.update_translations
       ( 'product.product'
       , 'description'
       , 472
       , value_en_us => 'Hotel, airfare, cab, etc.'
       , value_nb_no => 'Hotell, flybillett, taxi osv.'
       , value_sv_se => 'Hotell, flygbiljetter, taxi etc.'
       , value_da_dk => 'Hotel, flybillet, taxa osv.'
       , value_fi_fi => 'Hotelli, lentolippu, taksi jne.'
       , value_pt_pt => 'Hotel, bilhete de avião, táxi, etc.'
       );
end;

Set Language Permanently using settings*.xml / Connection String

The preferred language can currently be set permanently using the connection string. Add the following setting to the data container of Odoo of the desired database:

context-language=fr_FR

Set Language for Query Tool and Other On-premises Software

On the Invantive Query Tool, you can specify the desired language (without validation) by specifying it’s language code under the “Advanced” section:

image

Set Language for Invantive Cloud and Power BI

On Invantive Cloud, the desired language can be set using the connection string on the data container. In the next or future release, the “New Database” / “New Data Container” form might be extended by a text field to specify the desired language code.

Odoo and Non-installed languages

In BETA-release 23.1.219 it is possible to choose a non-existant language, such as fr.

When a non-installed language is specified, the tables silently fallback to the original language. This behaviour may change in the next or a future release to only allow the use of installed user interface languages.