Ticket #5789: 5789.patch
File 5789.patch, 3.7 KB (added by , 17 years ago) |
---|
-
django/utils/translation/trans_real.py
350 350 supported = dict(settings.LANGUAGES) 351 351 352 352 if hasattr(request, 'session'): 353 lang_code = request.session.get(' django_language', None)353 lang_code = request.session.get('_language', None) 354 354 if lang_code in supported and lang_code is not None and check_for_language(lang_code): 355 355 return lang_code 356 356 -
django/views/i18n.py
1 1 from django import http 2 from django.utils.translation import check_for_language, activate, to_locale, get_language 2 from django.utils.translation import check_for_language, activate, to_locale 3 from django.utils.translation import get_language 3 4 from django.utils.text import javascript_quote 4 5 from django.conf import settings 5 6 import os … … 26 27 lang_code = request.POST.get('language', None) 27 28 if lang_code and check_for_language(lang_code): 28 29 if hasattr(request, 'session'): 29 request.session[' django_language'] = lang_code30 request.session['_language'] = lang_code 30 31 else: 31 32 response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) 32 33 return response -
docs/i18n.txt
545 545 ``LocaleMiddleware`` tries to determine the user's language preference by 546 546 following this algorithm: 547 547 548 * First, it looks for a `` django_language`` key in the the current user's548 * First, it looks for a ``_language`` key in the the current user's 549 549 `session`_. 550 * Failing that, it looks for a cookie that is named according to your ``LANGUAGE_COOKIE_NAME`` setting. (The default name is ``django_language``, and this setting is new in the Django development version. In Django version 0.96 and before, the cookie's name is hard-coded to ``django_language``.)550 * Failing that, it looks for a cookie that is named according to your ``LANGUAGE_COOKIE_NAME`` setting. (The default name is ``django_language``, and this setting is new in the Django development version. In Django version 0.96 and earlier, the cookie's name is hard-coded to ``django_language``.) 551 551 * Failing that, it looks at the ``Accept-Language`` HTTP header. This 552 552 header is sent by your browser and tells the server which language(s) you 553 553 prefer, in order by priority. Django tries each language in the header … … 859 859 * Django doesn't use ``xgettext`` alone. It uses Python wrappers around 860 860 ``xgettext`` and ``msgfmt``. This is mostly for convenience. 861 861 862 -
tests/regressiontests/views/tests/i18n.py
16 16 post_data = dict(language=lang_code, next='/views/') 17 17 response = self.client.post('/views/i18n/setlang/', data=post_data) 18 18 self.assertRedirects(response, 'http://testserver/views/') 19 self.assertEquals(self.client.session[' django_language'], lang_code)19 self.assertEquals(self.client.session['_language'], lang_code) 20 20 21 21 def test_jsi18n(self): 22 22 """The javascript_catalog can be deployed with language settings"""