From a382e64ac1e5710a3206b542fab9443cfd59bfad Mon Sep 17 00:00:00 2001 From: "Nasreddin Boulif (bon)" Date: Sun, 25 Jun 2023 18:01:31 +0000 Subject: [PATCH] [FIX] im_livechat: display chatbot in website or user language Steps to reproduce: - Install the module `crm_livechat` - Activate another language (e.g. fr_FR) - Open a new incognito window and go to the website - On website, switch to the activated language - Open contact page - Open the chatbot Issue: The chatbot is displayed in `en_US`. Cause: The chatbot is displayed in the current user language (not website language). Public user have by default `en_US` as language. Solution: Retrieve the chatbot with the website activated language if set, otherwise, retrieve the chatbot in the user language. Fallback on `en_US`. opw-3284807 closes odoo/odoo#126594 X-original-commit: cb9c003700d2d8eb3be326260bae5fa5e599b89c Signed-off-by: Matthieu Stockbauer (tsm) Signed-off-by: Nasreddin Boulif (bon) --- addons/im_livechat/controllers/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/im_livechat/controllers/main.py b/addons/im_livechat/controllers/main.py index a2974c36ffa..1ad0b94135e 100644 --- a/addons/im_livechat/controllers/main.py +++ b/addons/im_livechat/controllers/main.py @@ -85,6 +85,8 @@ class LivechatController(http.Controller): # find the first matching rule for the given country and url matching_rule = request.env['im_livechat.channel.rule'].sudo().match_rule(channel_id, url, country_id) if matching_rule and (not matching_rule.chatbot_script_id or matching_rule.chatbot_script_id.script_step_ids): + frontend_lang = request.httprequest.cookies.get('frontend_lang', request.env.user.lang or 'en_US') + matching_rule = matching_rule.with_context(lang=frontend_lang) rule = { 'action': matching_rule.action, 'auto_popup_timer': matching_rule.auto_popup_timer, @@ -153,7 +155,8 @@ class LivechatController(http.Controller): chatbot_script = False if chatbot_script_id: - chatbot_script = request.env['chatbot.script'].sudo().browse(chatbot_script_id) + frontend_lang = request.httprequest.cookies.get('frontend_lang', request.env.user.lang or 'en_US') + chatbot_script = request.env['chatbot.script'].sudo().with_context(lang=frontend_lang).browse(chatbot_script_id) return request.env["im_livechat.channel"].with_context(lang=False).sudo().browse(channel_id)._open_livechat_discuss_channel( anonymous_name,