Reputation: 711
I'm doing some IP localization and need to set the language in a view. Using translation.activate changes the language, but the rendered page still have the default language prefix in its URL. Is there any way to also change the rendered URL?
thanks
jul
Upvotes: 0
Views: 844
Reputation: 396
Try to do in view same thing as LocaleURLMiddleware:
translation.activate(locale)
request.LANGUAGE_CODE = translation.get_language()
PS. Do you use {% url %} and {% locale_url %}?
Upvotes: 2
Reputation: 9173
The problem is that the middleware has already set the value of the language in the Request, so you will have to add your own middleware (after CommonMiddleware I believe). Inside your middleware class your process_request method will set the language and your process_response method will reset the language.
http://docs.djangoproject.com/en/dev/topics/http/middleware/
There may be a shortcut for not using middleware (manually setting the request LANGUAGE_CODE value and doing translation.activate within the view), but I have not tried anything like this.
Upvotes: 0