You can add a middleware to ignore the header:

class IgnoreLanguageHeaderLocaleMiddleware(LocaleMiddleware):

    LANGUAGE_HEADER = 'HTTP_ACCEPT_LANGUAGE'

    def process_request(self, request):
        if self.LANGUAGE_HEADER in request.META:
            del request.META[self.LANGUAGE_HEADER]

        super(IgnoreLanguageHeaderLocaleMiddleware,
self).process_request(request)


On Mon, Feb 24, 2020 at 1:44 PM Szocs Arnold <[email protected]>
wrote:

> Is there any solution to add language prefix to the URL from the
> settings.LANGUAGE_CODE which is my preferred language. Instead from
>  "Accept-Language" header. I do not want to use the browser language.
>
> On Fri, Feb 21, 2020 at 4:14 PM Aldian Fazrihady <[email protected]>
> wrote:
>
>> A web browser has language preference setting. When a request made to
>> your Django server,  your browser reads its language preferences and it put
>> it in the request "Accept-Language" header.
>> Django will check if the request URL has language prefix in it. If it
>> doesn't it will add language prefix to the same URL and make web browser to
>> redirect to that new URL.
>>
>> You can see the flow using web browser developer tool.
>>
>> On Fri, Feb 21, 2020 at 8:43 PM Szocs Arnold <[email protected]>
>> wrote:
>>
>>> I am using i18n_patterns to change the language prefix in url. It s
>>> working fine ones the language cookie is set. The problem is that it's
>>> adding /en/ when I trying to access a page without the language code in
>>> private window, even though my preferred language is not en (the default
>>> one set in settings.LANGUAGE_CODE). The Django documentation says that how
>>> django discovers language prefference:
>>>
>>> Django documentation says it will use the following to choose the
>>> language:
>>>
>>> First, it looks for the language prefix in the requested URL.Failing
>>>> that, it looks for the LANGUAGE_SESSION_KEY key in the current user’s
>>>> session.Failing that, it looks for a cookie. The name of the cookie used is
>>>> set by the LANGUAGE_COOKIE_NAME setting. (The default name is
>>>> django_language.) Failing that, it looks at the Accept-Language HTTP
>>>> header. This header is sent by your browser and tells the server which
>>>> language(s) you prefer, in order by priority. Django tries each language in
>>>> the header until it finds one with available translations. Failing that, it
>>>> uses the global LANGUAGE_CODE setting.
>>>>
>>>
>>> So the reason why I get /en/ prefix in my url, when there is no any
>>> cookie set is because of the Accept-Language HTTP header. How can i solve
>>> that if somebody visits my site for the first time when there is no cookie,
>>> the i18n to go to the final step to get the language from the global
>>> LANGUAGE_CODE?
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/5586da94-87bb-4879-b227-f8e29ce3e635%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/5586da94-87bb-4879-b227-f8e29ce3e635%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Regards,
>>
>> Aldian Fazrihady
>> http://aldianfazrihady.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAN7EoAbU5kUTc0UrX0etqp_s8bC4zK0L-wHpYNuoUB585DM7Og%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAN7EoAbU5kUTc0UrX0etqp_s8bC4zK0L-wHpYNuoUB585DM7Og%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABRfZM%2BbayBueLk68gC8NiQhrkisG8G%2B_OktDdOr9uR%3DW2yk_w%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CABRfZM%2BbayBueLk68gC8NiQhrkisG8G%2B_OktDdOr9uR%3DW2yk_w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Regards,

Aldian Fazrihady
http://aldianfazrihady.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN7EoAak5nkd9mMVGRbUXzZc5g2A885cwKfQZoPf4QTXTdxzVA%40mail.gmail.com.

Reply via email to