st4lk / django-solid-i18n-urls

[DEPRECATED] Use default language for urls without language prefix.
http://www.lexev.org/en/
Other
112 stars 29 forks source link

Does this package support Django 2^ ? #42

Open kentuck13 opened 6 years ago

kentuck13 commented 6 years ago

Question on title

Sharpek commented 5 years ago

Nope, but you can use https://docs.djangoproject.com/en/2.1/topics/i18n/translation/#django.conf.urls.i18n.i18n_patterns

ton77v commented 5 years ago

Is it possible to get the same functionality using i18n_patterns:

settings.SOLID_I18N_USE_REDIRECTS = True. In that case, for root paths (without prefix), django will try to discover user preferred language. If it doesn't equal to default language, redirect to path with corresponding prefix will occur. If preferred language is the same as default, then that request path will be processed (without redirect).

The problem is that if you make prefix_default_language=False, the redirect won't happen at all whatever language user prefers. I was so glad when found this package until discovered it doesn't work in Django 2

astagi commented 5 years ago

@ton77v try this one https://github.com/lotrekagency/djlotrek/blob/master/djlotrek/middleware/locale.py

It's a WIP and I've tested it only with prefix_default_language=False

This is how it works: if you don't have any language setting in session, it will use the browser language, otherwise it redirects you to the language you set. If you want to change the main language, you have to switch language manually.

Let me know if it works for you ;)

ton77v commented 5 years ago

@astagi thanks! looks good, hadn't chance to test it yet because I solved the problem long time ago with some hacks, and to be straight I don't want to touch that part of the code... for a while 😀

will test the next time when will have a chance

skabbit commented 2 years ago

@ton77v try this one https://github.com/lotrekagency/djlotrek/blob/master/djlotrek/middleware/locale.py

It's a WIP and I've tested it only with prefix_default_language=False

This is how it works: if you don't have any language setting in session, it will use the browser language, otherwise it redirects you to the language you set. If you want to change the main language, you have to switch language manually.

Let me know if it works for you ;)

I think, this isn't correct. With prefix_default_language=False root prefix / turns on default_language and doesn't respond to user browser settings. I've just checked it on Django 2.2.