Alter Odoo XmlRPC context to use a specific language

Viewed 4133

I need to get the translated data from odoo with a specific language using XMLRPC by default odoo sends data in the default language which is English

api.execute_kw(db, uid, pwd, 'res.country', 'search_read', [[]], {'fields': ['name']})

how to add context to this request to use a specific translation language.

3 Answers

let's say the endpoint is api you just need to add the param context as shown in the following code

api.execute_kw(db, uid, pwd, 'res.country', 'search_read', [[]], {'fields': ['id', 'name'], 'context' :{'lang': "fr_FR"}})

To complete @karara-mohamed answer, here what it looks like in a complete JSON-RPC API call (/jsonrpc):

{
    "jsonrpc": "2.0",
    "method": "call",
    "params": {
        "service": "object",
        "method": "execute_kw",
        "args": [
            "<database-name>",
            <user_id>,
            "<user_password>",
            "product.product",
            "search_read",
            [
                [
                   ["type", "=", "product"]
                ]
            ],
            {
                "fields": ["id", "name", "display_name"],
                "context": {
                    "lang": "fr_FR"
                },
                "limit": 5
            }
        ]
    },
    "id": <idRequest>
}
Related