Django behavior on translatable URL patterns (i18n_patterns) when prefix_default_language=False is used.

37 views
Skip to first unread message

Anthony Baillard

unread,
Apr 27, 2023, 9:31:18 AM4/27/23
to Django developers (Contributions to Django itself)
I have reported a few days ago an issue in Django 4.2 regarding translatable URL patterns: https://code.djangoproject.com/ticket/34515

Sarah Boyce (thank you Sarah) is working on a patch to fix the 404 issue: https://github.com/django/django/pull/16797

But, for now, we do not agree on the correct behavior in the case described. So, as she suggested (https://github.com/django/django/pull/16797#issuecomment-1524958085), I write to ask the community.

In brief:

1. Using i18n_patterns with default_prefix_language = True with 3 different languages (perfectly OK):
- /en/about/ goes to English page
- /es/a-proposito/ goes to Spanish page
- /fr/a-propos/ goes to French page

2. Using i18n_patterns with default_prefix_language = False with 3 different languages and default to english (perfectly OK):
- about/ goes to English page
- /es/a-proposito/ goes to Spanish page
- /fr/a-propos/ goes to French page

3. Using i18n_patterns with default_prefix_language = False with 3 different languages and default to french in Django 4.1 (seems OK to me):
- /en/about/ goes to English page
- /es/a-proposito/ goes to Spanish page
- /a-propos/ goes to French page

4. Using i18n_patterns with default_prefix_language = False with 3 different languages and default to french in Django 4.2 (bug report):
- /en/about/ goes to English page
- /es/a-proposito/ goes to Spanish page
- /a-propos/ raises HTTP 404 (because cookie or http header is not 'fr')

5. Using i18n_patterns with default_prefix_language = False with 3 different languages and default to french with Sarah's patch (what we do not agree on):
- /en/about/ goes to English page
- /es/a-proposito/ goes to Spanish page
- /a-propos/ redirects to /en/about/ (because cookie or http header is 'en')

IMO, behavior 3 is good (because it reproduces 1 without prefix). Sarah's and Nessita's opinion is that behavior 5 is correct.
More details in the issues and PR.

So, what do you think? Thank you!

Anthony 

Mariusz Felisiak

unread,
Apr 28, 2023, 1:07:17 AM4/28/23
to Django developers (Contributions to Django itself)
Anthony, please don't start the same discussion on multiple channels.

If anyone wants to add a comment, please do so in the forum.
Reply all
Reply to author
Forward
0 new messages