From 286cc97dd45a218ce763f9f15bc34f3226e13296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 11 Jul 2023 13:27:40 +0000 Subject: [PATCH] [IMP] web: allow lang to be overriden by url query params With this commit, it is possible to load the web client in a language different than the user by using the `lang=` query string in the url: For example, `/web?lang=en_US` This is useful when we need to quickly check something, without changing the current user settings. Note that it will only work if the url lang has been installed on the database (if lang does not exist, it will fall back to en_us). closes odoo/odoo#128121 Taskid: #3420252 Signed-off-by: Samuel Degueldre (sad) --- addons/web/controllers/home.py | 6 +++++- addons/web/views/webclient_templates.xml | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/addons/web/controllers/home.py b/addons/web/controllers/home.py index f82bc1e0678..92108fd351e 100644 --- a/addons/web/controllers/home.py +++ b/addons/web/controllers/home.py @@ -62,12 +62,16 @@ class Home(http.Controller): return request.redirect('/web/login?error=access') @http.route('/web/webclient/load_menus/', type='http', auth='user', methods=['GET']) - def web_load_menus(self, unique): + def web_load_menus(self, unique, lang=None): """ Loads the menus for the webclient :param unique: this parameters is not used, but mandatory: it is used by the HTTP stack to make a unique request + :param lang: language in which the menus should be loaded (only works if language is installed) :return: the menus (including the images in Base64) """ + if lang: + request.update_context(lang=lang) + menus = request.env["ir.ui.menu"].load_web_menus(request.session.debug) body = json.dumps(menus, default=ustr) response = request.make_response(body, [ diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml index 25b273d8e09..b924c1560fb 100644 --- a/addons/web/views/webclient_templates.xml +++ b/addons/web/views/webclient_templates.xml @@ -253,12 +253,18 @@