settings.py:
INSTALLED_APPS = [
...,
'modeltranslation',
]
TIME_ZONE = 'Europe/Belgrade'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LANGUAGES = (
('en-us', _('English')),
('hu', _('Hungarian')),
('sr-latn', _('Serbian')),
)
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
os.path.join(BASE_DIR, 'books', 'locale'),
)
urls.py:
urlpatterns = [
url(r'^i18n/', include('django.conf.urls.i18n')),
]
urlpatterns += i18n_patterns(
url(_r('^books/'), include('books.urls', namespace='books'))
)
My default language is english. My model has 3 title fields for each language. It is how modeltranslation package works i.e.:
(title_en, title_hu, title_sr_latn)
Since I use slug field for url representation of an instance of the model in the url, I have 3 slug fileds for each language accordingly in my model class too.
I don't see any sence that my url should look something like this on hungarian for example:
127.0.0.1/hu/konyvek/learn-django
I want my urls to look like this:
English url (I don't want to have language prefix for the default language!):
127.0.0.1/books/the-lord-of-the-rings
Hungarian url:
127.0.0.1/hu/konyvek/a-gyuruk-ura
Serbian url (it is unfortunate that serbian language prefix looks extreamly ugly but that is another topic):
127.0.0.1/sr-latn/knjige/gospodar-prstenova
I couldn't find anything so far that solves this problem.
It is obvious that I can't use either of these in my language switching 'next' form element's value in template:
{{ request.path }}
or {{ request.get_absolute_path|slice:'3:' }}
So I excluded the 'next' element temporarily.
When I'm switching languages, on my front page everything works well.
If I go to a books page for example (/hu/konyvek/)
, it shows the language properly but if I want from there to change to a different language it doesn't let me do it.
It just reloads the current page.
Any suggestion how to accomplish this?