Django i18n questions

42 views
Skip to first unread message

Andrew Pashkin

unread,
Apr 11, 2014, 1:55:12 AM4/11/14
to django...@googlegroups.com
Documentation says, that:
...it looks for a django_language key in the current user’s session
This is the latest commit if 1.4x branch of Django, but I can't even find word "session" in code with middleware. And It not working for me - I use it in combination with set_language view, and I checked it by debugger - while set_language switches language to needed one and puts it to "django_language" key, LocaleMiddleware ignores it. I'm not using 18n url patterns.

I also have tried to use prefixes, but in that case, by POST request, set_language uses next parameter to redirect user, which is might be "/en/", and even if language switches correctly to another one, response always will always be redirect to url with same language prefix as before - "/en/", so user will not see any effect.

Am I missing something?

-- 
С наилучшими пожеланиями, Андрей Пашкин.
м.т - +7 (985) 898 57 59
Skype - waves_in_fluids
e-mail - andrew....@gmx.co.uk

Andrew Pashkin

unread,
Apr 11, 2014, 2:04:06 AM4/11/14
to django...@googlegroups.com
I ended up using this snippet for switching languages. It simply reverses url with given language code.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/534783C0.9070406%40gmx.co.uk.
For more options, visit https://groups.google.com/d/optout.

Daniel Roseman

unread,
Apr 11, 2014, 4:45:21 AM4/11/14
to django...@googlegroups.com

On Friday, 11 April 2014 06:55:12 UTC+1, Andrew Pashkin wrote:
Documentation says, that:
...it looks for a django_language key in the current user’s session
This is the latest commit if 1.4x branch of Django, but I can't even find word "session" in code with middleware.

I'm not sure why you think the reference to the session has to be in that particular file. In fact what happens is that the process_request method of that middleware calls translation.get_language_from_request, which ends up here: https://github.com/django/django/blob/126d9e1b499663e72cc795906bdbcd333aceaf0a/django/utils/translation/trans_real.py#L366
which does indeed look up the session from the request.
-- 
DR.

Andrew Pashkin

unread,
Apr 11, 2014, 12:11:57 PM4/11/14
to django...@googlegroups.com
Indeed
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages