* cc: Mariusz Felisiak (removed)
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Mariusz Felisiak):
Replying to [comment:1 ab]:
> Expected behavior:
[https://docs.djangoproject.com/en/4.2/topics/i18n/translation/#how-
django-discovers-language-preference django 4.2 documentation]
>
> LocaleMiddleware tries to determine the user’s language preference by
following this algorithm:
>
> - First, it looks for the language prefix in the requested URL. This is
only performed when you are using the i18n_patterns function in your root
URLconf. See Internationalization: in URL patterns for more information
about the language prefix and how to internationalize URL patterns.
>
> - 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.
IMO it still works that way. However, in Django 4.2
`get_language_from_request()` returns the language from a request (`en`
for me) which is activated and the default path `about/` is no longer
translated to the `a-propos/`. This is definitely a change from the
previous behavior.
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:4>
Comment (by ab):
Replying to [comment:4 Mariusz Felisiak]:
>
> IMO it still works that way. However, in Django 4.2
`get_language_from_request()` returns the language from a request (`en`
for me) which is activated and the default path `about/` is no longer
translated to the `a-propos/`. This is definitely a change from the
previous behavior.
Thank you Mariusz for the quick reaction.
I agree it still globally works that way, nevertheless, in the case I
describe, when django looks for the language prefix in the requested URL
and there is not language prefix, I would expect django to return "fr",
not to go to the next steps of the algorithm. Because I want
`prefix_default_language = False` to take precedence on cookies or
headers. Does it make sense?
I need to add that I use `translate_url` to
[https://github.com/aboutofpluto/django-prefix-default-language-bug-
report/blob/master/prefix/urls.py#L11 build the links] in my templates.
Consequently, my URLs are translated in the template **only** (hence the
404).
So you're right about the default path not being translated anymore.
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:5>
* cc: sergioisidoro (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:6>
* owner: nobody => Sota Tabu
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:7>
* owner: Sota Tabu => Sarah Boyce
Comment:
I have a PR with what I think the issue is, but not confident
https://github.com/django/django/pull/16797
@ab I think what you're saying makes sense
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:8>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:9>
Comment (by David Sanders):
>I agree it still globally works that way, nevertheless, in the case I
describe, when django looks for the language prefix in the requested URL
and there is not language prefix, I would expect django to return "fr",
not to go to the next steps of the algorithm. Because I want
prefix_default_language = False to take precedence on cookies or headers.
Does it make sense?
My 2¢: Is ignoring the process for determining the language the least
surprising choice here though? It all depends on whether no-prefix URL
should refer to a user setting or the site's default language. I mean imho
navigating to a URL I might expect it to show the language in what I chose
🤷♂️
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:10>
* keywords: internationalization, i18n, prefix_default_language =>
internationalization, i18n, prefix_default_language, i18n_patterns
Comment:
@Sarah: yes, it is the same problem. After investigating the code, the
change in behavior is linked to the fact that `get_language_from_path`
returns `None` when the url is not prefixed. So, the cookie is used (or
the `Accept-Language` header sent by the browser).
@David: thanks for your contribution, but I do not fully agree. If
`prefix_default_url` is `True`, the language is correctly detected by
django based on the URL. If I set `prefix_default_url` to `False` I expect
the same behavior for the default language without prefix. When I decide
do use `i18n_patterns` at least (I have just added this tag to the
ticket).
When `i18n_patterns`is not used, I agree with you.
So the problem might come from i18n_patterns not calling/handling
correctly the calls to the new `get_language_*` functions.
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:11>
Comment (by ab):
@sarah: I'll test your patch because your edits might solve the problem
with HTTP headers too. Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:12>
Comment (by ab):
Just to keep track of the current work on this issue, there is a
discussion about how django should behave here:
https://github.com/django/django/pull/16797#issuecomment-1524958085
As suggested by Sarah, I'll post to django-developers for a wider range of
opinions.
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:13>
Comment (by Mariusz Felisiak):
[https://forum.djangoproject.com/t/django-behavior-on-translatable-url-
patterns-i18n-patterns-when-prefix-default-language-false-is-used/20564
Django forum discussion].
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:14>
Comment (by Mariusz Felisiak):
Alternative [https://github.com/django/django/pull/16810 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:15>
* status: assigned => closed
* resolution: => fixed
Comment:
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/34515#comment:16>
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/34515#comment:17>
Comment (by ab):
Thank you for working on this and maintaining django so well!
Anthony
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:18>