Access multiple translations of a field in Tryton
written on Friday, June 3, 2016
At work, we are currently migrating away from a proprietary ERP software package to Tryton. There are several reasons why we decided to switch and one them is that Tryton provides an API and sane data access. Being a free software project, there are libraries and tools available to get access to the data. This is a good foundation to build your own tools on top.
Tryton provides a client library called Proteus for programmatic data access. The first tool that I built on top of Proteus is called pedantic bot. It nags about inconsistencies and errors in the database. For example, the pedantic bot checks for the following issues:
- Leading/trailing whitespace in fields
- Control characters in fields
- Inconsistent formatting of fields (phone numbers, …)
- Incomplete data records (e.g. contact information is missing)
- Missing descriptions
- …
Tryton allows to translate some of the fields where it makes sense to have them available in multiple languages (product name, a description, payment terms, …). The pedantic bot should check all the translations alike. It took me a while to figure out how to get access to a field in a particular translation, so here is a short demo on how to accomplish it in Tryton 3.8. It should work on other versions too:
Save this script as example.py, install Proteus and run:
The solution is to set the desired language in the context: with current_config.set_context({'language': 'en_US'}). Have fun.