Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
1508 Widoki

Hi Odoo developers, 


I need to set the default browsing language of the website to Arabic so that when someone browses the website for the first time sees the content in Arabic and the language selector shows Arabic as the default option, not English


I tried to set the default language of the website to Arabic but the result was not the same as I wanted.


Thanks in advance for your replies.

Awatar
Odrzuć
Autor

Thanks for the reply,

Your solution seems interesting, but the get_response is not defined in the website module so I do not know where I need to intercept the request correctly

I will follow your lead 

Best regards

ok, I did not test the code myself, but just try the idea, you may search in the odoo source code for where the method def get_response is defined and then inherit that model and try.

best wishes

Najlepsza odpowiedź

HOW did you set the default language of your Website?

Did you follow the documentation?

https://www.odoo.com/documentation/17.0/applications/websites/website/configuration/translate.html


WHAT was the result?  It is hard to answer your question because we don't know what you tried and what you mean by "not the same as I wanted".


Something you should know about how Odoo sets the language on the Website:

1) First, Odoo checks the GeoIP of the user. Basically, what location in the world is the User accessing the database from. If the country code for that location has a default language that matches one from the Website, Odoo will use that first.

2) Second, Odoo checks the browser language set for the User's browser. Similarly to the approach above, if that language code matches one from the Website, Odoo will use that.

3) Last, Odoo will check the default language set on the Website and use that.


As you can see the default language on the website is only used if Odoo can't determine the language using the first two approaches.


Awatar
Odrzuć
Autor

Thank you for the clear explanation

Yes I did change the default language from website settings but it always shows English first when browsing.

I am browsing from Kuwait and my browser lang is English but I expected that odoo ignore the detection from geo and the browser lang and show me the website from default language I selected.

Best regards

We are trying to be as helpful as we can to the visitor, since the browser is set to English in your case, but it may not be what you want in all cases.

@Ray Carnes (ray)

Are you sure about point 1, that the odoo ecommerce checks the GeoIP of the user surfing to the site and changes language accordingly if the language is installed?

I cannot get it working.
Only point 2 where it checks the browser language.

I'd rather use GeoIP where odoo ecommerce checks the IP address.

Najlepsza odpowiedź

in your  custom module, you can try something like below 

from odoo import models, http

from odoo.http import request


class Website(models.Model):

    _inherit = 'website'


    def get_response(self, path, query_string, anchor, response=None):

        # Check if the user is visiting for the first time (no cookies set)

        if not request.httprequest.cookies.get('visited_before'):

            # Force Arabic language

            lang_code = 'ar'

            request.env['ir.http']._set_cookie_language(lang_code)

           

            # Redirect to Arabic version of the page

            url = request.httprequest.url.replace('/en/', f'/{lang_code}/')

            return request.redirect(url)

       

        # Set a cookie to indicate that the user has visited

        response = super(Website, self).get_response(path, query_string, anchor, response)

        response.set_cookie('visited_before', '1')

        return response


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
kwi 24
2426
0
sty 23
1945
1
kwi 21
4876
2
lis 17
4302
0
wrz 24
824