Help

2

When navigate from Odoo website to odoo backend language doesn't load

Avatar
Mitul Shingala

Hello,

I am using odoo11. i have enable multi language feature for eg English, French, Spanish.  My problem is into website side when i switch the language english to french and go to backend at that time odoo loads the menu into english language not into french language. but once the page is reload into backend after that it will reload the menu into the french language. 

I want the language into odoo backend  which is user switch on odoo frontend

Please help me to resolve the issue.

Thanks in advance.

Avatar
Discard
2 Answers
1
Avatar
Mitul Shingala
Best Answer

Hello All,

I have found the solution of this problem and it works fine as i need. here i put some code. When user switch  language into website, so one controller is call and into that controller i have update my code. Whatever new language is select by user on website at that time i have updated that language into user language field(in backend). and update the context value. so now when user goes to backend, at that time user get the GUI in newly selected language which is selected by user on website.

CODE: 

from odoo.addons.website.controllers.main import Website
from odoo.http import request
class WebsiteExt(Website):
    @http.route()
    def change_lang(self, lang, r='/', **kwargs):
    # this controller call when user switch the language into website
        res = super(WebsiteExt, self).change_lang(lang, r, **kwargs) # super call of the change_lang()
        if not request.env.user._is_public():
            request.env.user.partner_id.lang = lang
            request.env.user.lang = lang
            request.env['ir.http'].webclient_rendering_context() # call this method so the menu and session data will be reload.
        return res

Avatar
Discard
0
Best Answer

Hi,

You have to set the cookie by frontend_lang parameter when you redirect from website to /web url.

Or

You can reload your page when user click on any menuitem and redirect to page by javascript.

1 Comment
Avatar
Discard
Avatar
Mitul Shingala
-

Thanks for your answer. i have also tried this frontend_lang parameter but doesn't work.