the last code has a bug, here is the new one, and sorry :) class LocaleURLMiddleware: def get_language_from_request (self,request): from django.conf import settings import re supported = dict(settings.LANGUAGES) lang = settings.LANGUAGE_CODE[:2] check = re.match(r"/(\w\w)/.*", request.path) changed = False if check is not None: t = check.group(1) if t in supported: lang = t if hasattr(request, 'session'): request.session['django_language'] = lang else: response.set_cookie('django_language', lang) changed = True if not changed: if hasattr(request, 'session'): lang = request.session.get('django_language', None) if lang in supported and lang is not None: return lang
lang = request.COOKIES.get('django_language', None) if lang in supported and lang is not None: return lang return lang def process_request(self, request): language = self.get_language_from_request(request) translation.activate(language) request.LANGUAGE_CODE = translation.get_language() def process_response(self, request, response): patch_vary_headers(response, ('Accept-Language',)) translation.deactivate() return response --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---