Issue #25 open

Using PREFIX_DEFAULT_LOCALE = False with LOCALEURL_USE_ACCEPT_LANGUAGE = True, doesn't really work

Anonymous created an issue

Using the following settings:


A browser that doesn't accept Dutch (nl) or has Dutch as a lower priority that for example English. Will not be able to switch to Dutch content.

Instead the browser will alway be redirected to the English version.

This is because LocaleURLMiddleware doesn't take into account the possibility that urls are not prefixed for the default language.

I'm not sure what a good workaround would be.

Comments (4)

  1. Carl Meyer repo owner
    • changed status to open

    Thanks for the report!

    It seems to me that this is an unavoidable consequence of the combination of PREFIX_DEFAULT_URL = False and LOCALEURL_USE_ACCEPT_LANGUAGE = True. The settings are simply incompatible, as they request two mutually exclusive behaviors for an unprefixed URL.

    I'd propose that the only reasonable solution here is documentation that those two settings should not be used together. Possibly could also change the middleware to ignore LOCALEURL_USE_ACCEPT_LANGUAGE if PREFIX_DEFAULT_URL is set to False.

  2. Jaap Roes

    I was looking around the forks of this project and came across this changeset:

    It seems to fix this issue (haven't tested it). It uses the language set in the session or language cookie so unprefixed urls work, as long as a language switch manipulates the session/language cookie.

    It would be nice to be able to detect the user's preferred language and not having to prefix the urls of the default language at the same time. It doesn't seem to be completely unavoidable, but it would require localeurl to take into account the Django locale session/cookie. Which is previously just ignored.

  3. Carl Meyer repo owner

    We've now got a similar session fallback in localeurl tip, but I don't think that solves the problem here, it just moves it. If you use the session fallback with ``PREFIX_DEFAULT_URL = False``, the user won't get your default language with an unprefixed URL, they'll get redirected to whatever language is set in their session.

    I think the correct solution here is to document that if you set ``PREFIX_DEFAULT_URL = False`` you are requesting that an unprefixed URL activate your preset default language, and therefore neither ``LOCALEURL_USE_ACCEPT_LANGUAGE`` nor ``LOCALEURL_USE_SESSION`` will have any effect. And, of course, modify the middleware such that this is actually the case.

  4. Jaap Roes

    OK, in my case this issue was eventually resolved by just convincing the client that these two settings do not go together.

    I did some testing with the develop version and it seems that the behavior I wanted to achieve is now possible.

    Using a form that submits to 'django.conf.urls.i18n' it's possible to explicitly set your preferred language. If it happens to be set to the default language the unprefixed urls become usable. If not, the unprefixed url redirects to the set language, which is expected. So I don't think the middleware needs to be changed.

  5. Log in to comment