In brief: `prefix_default_language = False` raises HTTP 404 for the
default unprefixed pages if `LANGUAGE_CODE` is not "en".
I think the problem is that the function `get_language_from_path` in
`django/utils/translation/trans_real.py` returns `None` in case of failure
instead of `LANGUAGE_CODE`:
[https://github.com/django/django/commit/94e7f471c4edef845a4fe5e3160132997b4cca81
#diff-cc1f617ac65a58aec8f73b7a909c5bb48e0391543fe64c4f7ee22d4333a529efL585
diff in 4.2]
Consequently, other mechanisms are used to get the language (cookies or
headers) that do not work neither.
Related issue with my last comment adding some extra context:
[https://code.djangoproject.com/ticket/34455]
It is the first time I contribute to django, I hope the bug report is OK.
I am also willing to write the patch and test if required.
--
Ticket URL: <https://code.djangoproject.com/ticket/34515>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34515#comment:1>