I am using i18n_patterns to change the language prefix: /fr/ /de/ etc. It's working beautifully.
The only problem it's adding /en/ when trying to access a page without the language code.
I am wondering how I can have English as the default language and not having /en/ with every URL for the English version.
Thanks.
There is a package called django-solid-i18n-urls, that will do, what you want.
One thing to mention: it is not using redirects at all. So, if the user will come to site and his preferred language is not en (the default one set in settings.LANGUAGE_CODE) but for example fe, he will not be redirected to /fe/, he has to do it manually.
If you still want to use redirects, it is possible to modify the code, luckily it is not much there.
Here how you can install it (more detailed install sequence in readme):
1) pip install solid_i18n
2) Specify language for root urls in settings.py: LANGUAGE_CODE = 'en'
3) Add SolidLocaleMiddleware instead of LocaleMiddleware to MIDDLEWARE_CLASSES:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'solid_i18n.middleware.SolidLocaleMiddleware',
'django.middleware.common.CommonMiddleware',
)
4) Use solid_i18n_patterns instead of i18n_patterns
from django.conf.urls import patterns, include, url
from solid_i18n.urls import solid_i18n_patterns
# urls without language, this can be skipped
urlpatterns = patterns(''
# ...
)
# urls, that must have default language at root url and prefixes for other languages
urlpatterns += solid_i18n_patterns('',
url(r'^about/$', 'about.view', name='about'),
# ...
)
This blog is running using mentioned package, where root url (without prefix) renders russian language.
Article, why redirects are not used.
UPDATED
Mentioned package now have SOLID_I18N_USE_REDIRECTS option. If True, preferred language will be discovered and either redirect to non-default language url will occur, either (if discovered language is equal to default) url without prefix will be shown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With