However, I noticed that `get_language_from_request` falls back to the
settings default language, which will almost always take precedence in
this case.
This is quite confusing, since `settings.LANGUAGE_CODE` is not "from the
request", but from the application configuration, and it feels that the
responsibility of falling back to the default language should lie in the
Middleware, not in this function.
--
Ticket URL: <https://code.djangoproject.com/ticket/34069>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> I'm writing a middleware to fallback to a different language depending on
> the TLD of the domain of the HTTP_HOST
>
> However, I noticed that `get_language_from_request` falls back to the
> settings default language, which will almost always take precedence in
> this case.
>
> This is quite confusing, since `settings.LANGUAGE_CODE` is not "from the
> request", but from the application configuration, and it feels that the
> responsibility of falling back to the default language should lie in the
> Middleware, not in this function.
New description:
I'm writing a middleware to fallback to a different language depending on
the TLD of the domain of the HTTP_HOST
However, I noticed that `get_language_from_request` falls back to the
settings default language, which will almost always take precedence in
this case.
This is quite confusing, since `settings.LANGUAGE_CODE` is not "from the
request", but from the application configuration, and it feels that the
responsibility of falling back to the default language should lie in the
Middleware, not in this function.
Solution / Summary: `get_language_from_request` should return None, to
communicate to the middleware that there was no language from request, and
that the middleware should fallback to the default. Otherwise if the
`get_language_from_request` returns "EN" we don't know if "EN" is actually
a request preference, or because it came from the default
`settings.LANGUAGE_CODE`
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:1>
* has_patch: 0 => 1
Comment:
Here's a draft PR for this issue:
https://github.com/django/django/pull/16142
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:2>
* stage: Unreviewed => Accepted
Comment:
Reading the rationale and looking at the draft PR, I'm rather sympathetic
to the idea.
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:3>
* owner: nobody => Aman Pandey
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:4>
* needs_docs: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:5>
* owner: Aman Pandey => sergioisidoro
Comment:
Hi Aman,
Sorry the ticket is already being worked on by sergioisidoro :)
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:6>
Comment (by Aman Pandey):
Replying to [comment:6 David Sanders]:
> Hi Aman,
>
> Sorry the ticket is already being worked on by sergioisidoro :)
ohh it's fine , my bad i took it without noticing .
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:7>
* needs_docs: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"94e7f471c4edef845a4fe5e3160132997b4cca81" 94e7f47]:
{{{
#!CommitTicketReference repository=""
revision="94e7f471c4edef845a4fe5e3160132997b4cca81"
Fixed #34069 -- Made LocaleMiddleware respect language from requests when
i18n patterns are used.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:9>
* has_patch: 1 => 0
* resolution: fixed => duplicate
* easy: 1 => 0
* stage: Ready for checkin => Unreviewed
Comment:
Duplicate of #29425, see [https://forum.djangoproject.com/t/django-
behavior-on-translatable-url-patterns-i18n-patterns-when-prefix-default-
language-false-is-used/20564/1 discussion].
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:10>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"0e444e84f87d174713a2aef0c4f9704ce2865586" 0e444e8]:
{{{
#!CommitTicketReference repository=""
revision="0e444e84f87d174713a2aef0c4f9704ce2865586"
Fixed #34515 -- Made LocaleMiddleware prefer language from paths when i18n
patterns are used.
Regression in 94e7f471c4edef845a4fe5e3160132997b4cca81.
This reverts commit 94e7f471c4edef845a4fe5e3160132997b4cca81
(refs #34069) and
partly reverts commit 3b4728310a7a64f8fcc548163b0aa5f98a5c78f5.
Thanks Anthony Baillard for the report.
Co-Authored-By: Sarah Boyce <42296566+...@users.noreply.github.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:11>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"f200d8369822e418906579503b8d3015a03e75f0" f200d836]:
{{{
#!CommitTicketReference repository=""
revision="f200d8369822e418906579503b8d3015a03e75f0"
[4.2.x] Fixed #34515 -- Made LocaleMiddleware prefer language from paths
when i18n patterns are used.
Regression in 94e7f471c4edef845a4fe5e3160132997b4cca81.
This reverts commit 94e7f471c4edef845a4fe5e3160132997b4cca81
(refs #34069) and
partly reverts commit 3b4728310a7a64f8fcc548163b0aa5f98a5c78f5.
Thanks Anthony Baillard for the report.
Co-Authored-By: Sarah Boyce <42296566+...@users.noreply.github.com>
Backport of 0e444e84f87d174713a2aef0c4f9704ce2865586 from main
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34069#comment:12>