I have internationalization correctly installed.
It's works with urls like:
/en/bookings/ #English
/es/reservas/ #Spanish
In the home page the language switching works fine too.
- What's the issue?
When I change the language in a translated page, like /en/bookings/, if I turn the language to Spanish (es) I am redirected to /en/bookings/ again and I see the page in English.
If I change the prefix (like this answer) the redirection goes to /es/bookings/ that doesn't exists.
I don't want to be redirected to the home page.
- What I like?
If I am in the /en/bookings/ and switch to Spanish I want to be redirected to /es/reservas/, for all the translated urls.
What is the best way?
Thanks.
When I had the same problem, I implemented a custom template tag (current_url) that, given the request in context, re-renders the url for the active language:
Here is the code for the custom tag (custom_tags.py):
There is no need to use the 'set_language' django view. There is no need to make a POST request to change the active language. With only html archors linking all your internationalized content together, it's better for SEO.
I had similar problem so I sending my resolution to save Your time.
main(urls.py)
(index.urls.py)
Creating template tag to return urls for current location in all languages that we support (index.templatetags.helper_tags.py)
Creating middleware to change site language when user will click at alternative link to this sub site but in different language (middleware.py)
Adding it to (settings.py) just after LocaleMiddleware
Sample usage in template: