#35009: set_language doesn't work with prefix_default_language=False
-----------------------------------------+------------------------
               Reporter:  killianarts    |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  Uncategorized  |        Version:  4.2
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 Using `set_language`, without setting the `next` parameter in the request,
 doesn't redirect to the default language when
 `prefix_default_language=False` in i18n_patterns(). If
 `prefix_default_language=True`, and I manually enter the page with the
 default language code in the url one time after setting
 `prefix_default_language=True`, `set_language` will redirect to and from
 the default language as expected.

 {{{#!django
 {% get_current_language as CURRENT_LANGUAGE_CODE %}
 {% get_available_languages as AVAILABLE_LANGUAGES %}
 {% get_language_info_list for AVAILABLE_LANGUAGES as languages %}
 {% for lang in languages %}
   {% if lang.code != CURRENT_LANGUAGE_CODE %}
     <form id="language-switcher"
           action="{% url 'set_language' %}"
           method="post">
       {% csrf_token %}
       <input name="language" type="hidden" value="{{ lang.code }}">
       <button type="submit">{{ lang.name_local }}</button>
     </form>
   {% endif %}
 {% endfor %}
 }}}

 {{{#!python
 urlpatterns = i18n_patterns(
     path('admin/', admin.site.urls),
     path('', include('core.urls')),
     path('contact/', include('contact.urls')),
     path('articles/', include('articles.urls')),
     prefix_default_language=False,
 )
 urlpatterns += [path("i18n/", include("django.conf.urls.i18n")),]
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/35009>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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-updates/0107018c2245719e-4f2071be-c415-4334-9e2f-64c548c23388-000000%40eu-central-1.amazonses.com.

Reply via email to