OpenERP 7 : How to load a language from a module

OpenERP 7 : How to load a language from a module

Preloading a language translation in a customer module is as simple as writing a few lines of XML. The technique is to simulate the use of the language wizard below, that can be found in the settings → Translations → Load a translation menu:

Now if you want to automate this language installation during a customer module installation, you have to remember that a wizard is just an objet managed by a TransientModel, exactly like any other model. The first step is to create the object with a record:

<record model="base.language.install"
        id="install_tr">
    <field name="lang">tr_TR</field>
    <field name="state">done</field>
    <field name="overwrite" eval="1"/>
</record>

Since OpenERP 6.1 this kind of transient objects are created in the database so that the wizard is stateless and can be handled by any OpenERP server backend (in a multi-server configuration). Then they are automatically deleted after 30 min by a scheduled action.

Creating this object is not enough to load the language, as the wizard does not do anything until you click on the "Load" button.

So the next step is to simulate the click on the "Load" button. This can easily be done by a <function> tag pointing to the wizard object :

<function
	model="base.language.install"
	name="lang_install" 
	eval="[[ref('install_tr')]]" 
/>

It means : run the lang_install function of the existing base.language.install transient object, and pass a list of arguments to it, containing the ids of this same object.

The final result is a simple lang.xml file containing :

<openerp>
  <data noupdate="1">
    <record model="base.language.install" id="install_tr">
      <field name="lang">tr_TR</field>
      <field name="state">done</field>  
      <field name="overwrite" eval="1"/>
    </record>
    <function model="base.language.install"
              name="lang_install"
              eval="[[ref('install_tr')]]"/>
  </data>
</openerp>