User language

Topics: OpenErpNet Connector
Jan 21, 2014 at 4:34 PM
Hello Jlob,

thanks for the connector.

I'm able to read and write data. But how do I set the user language in the connection context? If I read data from stock.location, for example, I don't get the translated results.

Thanks,

jev
Coordinator
Mar 6, 2014 at 11:21 AM
i'm afraid you cannot set language in connection. If you need translations you need to query against ir.translation model
May 13, 2014 at 9:36 AM
Jlob wrote:
i'm afraid you cannot set language in connection. If you need translations you need to query against ir.translation model
Sorry for necroposting, but may be you will find it useful. I'm using my own connector which is very similar to your project. It's possible to set context arguments actually. All you need is to add context argument to Read\Execute methods like this:
[XmlRpcMethod("execute")]
object[] Read(string dbName, int userId, string password, string model, string method, object[] ids, object[] fields, object context);

[XmlRpcMethod("execute")]
object[] ReadMetadata(string dbName, int userId, string password, string model, string method, object[] ids, object context);

[XmlRpcMethod("execute")]
object Execute(string dbName, int userId, string password, string model, string method, object arg0, object context);
The context is created during OpenERP login:
var context = new XmlRpcStruct {{"lang", language}};
where 'language' is string variable, for example, "en_US". If this variable didn't specified, then I'm using user's language from OpenERP: res.users.lang
Coordinator
May 13, 2014 at 10:45 AM
Very interesting, i will take a look ASAP.

Thanks¡¡¡¡
May 13, 2014 at 12:41 PM
It's working!
Thanks v1rusw0rm!!!
May 15, 2014 at 4:29 PM
I've to correct my last reply.
I try to get the translated complete_name of stock.location. Here's what I'm trying to do:
XmlRpcStruct xrsContext = new XmlRpcStruct { { "lang", "de_DE" }, { "tz", "Europe/Berlin" } };
object[] result = oerp.read(dbName,userId,pwd, "stock.location", "read", ids, new object[] { "id", "name", "complete_name", "usage", "stock_real", "stock_virtual", "chained_picking_type" }, xrsContext);
I'm getting all stock locations, but the complete name is not translated.

Do you have an idea how I can get the location translated?
May 15, 2014 at 4:40 PM
May be complete_name isn't translated because it's functional field? In our project all of translatable fields are simple char fields so I didn't test how it works with functions.