Opened 5 months ago

Closed 5 months ago

#35009 closed Bug (duplicate)

set_language doesn't work with prefix_default_language=False

Reported by: KILLIAN.arts Owned by: nobody
Component: Uncategorized Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

{% 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 %}
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")),]

Change History (2)

comment:1 by KILLIAN.arts, 5 months ago

I just tried set_language with a fresh install and it has the same issue.

comment:2 by Mariusz Felisiak, 5 months ago

Resolution: duplicate
Status: newclosed

Duplicate of #28567.

Note: See TracTickets for help on using tickets.
Back to Top