Index: django/utils/cache.py
===================================================================
--- django/utils/cache.py	(revision 9532)
+++ django/utils/cache.py	(working copy)
@@ -29,6 +29,7 @@
 from django.utils.encoding import smart_str, iri_to_uri
 from django.utils.http import http_date
 from django.utils.hashcompat import md5_constructor
+from django.utils import translation
 
 cc_delim_re = re.compile(r'\s*,\s*')
 
@@ -136,16 +137,21 @@
                           if newheader.lower() not in existing_headers]
     response['Vary'] = ', '.join(vary_headers + additional_headers)
 
-def _generate_cache_key(request, headerlist, key_prefix):
+def _generate_cache_key(request, headerlist, key_prefix):    
     """Returns a cache key from the headers given in the header list."""
     ctx = md5_constructor()
     for header in headerlist:
         value = request.META.get(header, None)
         if value is not None:
             ctx.update(value)
-    return 'views.decorators.cache.cache_page.%s.%s.%s' % (
+    cache_key =  'views.decorators.cache.cache_page.%s.%s.%s' % (
                key_prefix, iri_to_uri(request.path), ctx.hexdigest())
 
+    if settings.USE_I18N:
+        cache_key += ".%s" % translation.get_language()
+    return cache_key
+
+
 def get_cache_key(request, key_prefix=None):
     """
     Returns a cache key based on the request path. It can be used in the
@@ -155,11 +161,14 @@
 
     If there is no headerlist stored, the page needs to be rebuilt, so this
     function returns None.
-    """
+    """    
     if key_prefix is None:
         key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
                     key_prefix, iri_to_uri(request.path))
+    if settings.USE_I18N:
+        cache_key += ".%s" % translation.get_language()
+ 
     headerlist = cache.get(cache_key, None)
     if headerlist is not None:
         return _generate_cache_key(request, headerlist, key_prefix)
@@ -183,8 +192,12 @@
         key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
     if cache_timeout is None:
         cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
+
     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
-                    key_prefix, iri_to_uri(request.path))
+                    key_prefix, iri_to_uri(request.path))    
+    if settings.USE_I18N:
+        cache_key += ".%s" % translation.get_language()
+        
     if response.has_header('Vary'):
         headerlist = ['HTTP_'+header.upper().replace('-', '_')
                       for header in cc_delim_re.split(response['Vary'])]
Index: django/middleware/cache.py
===================================================================
--- django/middleware/cache.py	(revision 9532)
+++ django/middleware/cache.py	(working copy)
@@ -68,6 +68,7 @@
 
     def process_response(self, request, response):
         """Sets the cache, if needed."""
+
         if not hasattr(request, '_cache_update_cache') or not request._cache_update_cache:
             # We don't need to update the cache, just return.
             return response

Property changes on: tests/regressiontests/cachei18n
___________________________________________________________________
Added: svn:ignore
   + __init__.pyc


Index: tests/regressiontests/cachei18n/views.py
===================================================================
--- tests/regressiontests/cachei18n/views.py	(revision 0)
+++ tests/regressiontests/cachei18n/views.py	(revision 0)
@@ -0,0 +1,18 @@
+#/usr/bin/env python
+# -*- coding: UTF-8 -*-
+from django.shortcuts import render_to_response
+from django.views.decorators.cache import cache_page
+
+RECORDS_PER_PAGE=2
+VISIBLE_PAGES=3
+
+@cache_page(3600)
+def app_index(request, page=1):
+    "Home page with pagination. Adapted to the trunk version of paginator"
+    data['content'] = "this is a test"    
+    response = render_to_response('agenda/index.html',data)
+    return response
+
+
+
+
Index: tests/regressiontests/cachei18n/__init__.py
===================================================================
--- tests/regressiontests/cachei18n/__init__.py	(revision 0)
+++ tests/regressiontests/cachei18n/__init__.py	(revision 0)
@@ -0,0 +1,2 @@
+__author__="aaloy"
+__date__ ="$21/11/2008 09:55:21$"
\ No newline at end of file
Index: tests/regressiontests/cachei18n/settings.py
===================================================================
--- tests/regressiontests/cachei18n/settings.py	(revision 0)
+++ tests/regressiontests/cachei18n/settings.py	(revision 0)
@@ -0,0 +1,86 @@
+# Django settings for test2 project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+DATABASE_NAME = '/tmp/test.sqlite'             # Or path to database file if using sqlite3.
+DATABASE_USER = ''             # Not used with sqlite3.
+DATABASE_PASSWORD = ''         # Not used with sqlite3.
+DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = 'il_uk6kwtuj4&(n$o*u-2x$k+f54r02)*zw+b+sx_g%puw6@b('
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+#     'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',    
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.locale.LocaleMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+)
+
+ROOT_URLCONF = 'test2.urls'
+
+TEMPLATE_DIRS = (
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+)
+
+LANGUAGES = (
+    ('en', 'English'),
+    ('es', 'Spanish'),
+)
+
Index: tests/regressiontests/cachei18n/tests.py
===================================================================
--- tests/regressiontests/cachei18n/tests.py	(revision 0)
+++ tests/regressiontests/cachei18n/tests.py	(revision 0)
@@ -0,0 +1,115 @@
+# -*- coding: UTF-8 -*-
+
+from django.core.cache import cache
+from django.core.cache import get_cache
+from django.core.cache.backends.filebased import CacheClass as FileCache
+from django.http import HttpRequest
+from django.http import HttpResponse
+from django.utils import cache
+from django.utils import translation
+
+import shutil
+import tempfile
+import unittest
+from django.conf import settings
+from django.middleware.cache import FetchFromCacheMiddleware, UpdateCacheMiddleware
+
+
+
+
+class Cache(unittest.TestCase):
+    def setUp(self):
+        # Special-case the file cache so we can clean up after ourselves.
+        if isinstance(cache, FileCache):
+            self.cache_dir = tempfile.mkdtemp()
+            self.cache = get_cache("file:///%s" % self.cache_dir)
+        else:
+            self.cache_dir = None
+            self.cache = cache
+        settings.LANGUAGES = (
+                ('en', 'English'),
+                ('es', 'Spanish'),
+        )
+
+    def tearDown(self):
+        if self.cache_dir is not None:
+            shutil.rmtree(self.cache_dir)
+
+    def _get_request(self):
+        request = HttpRequest()
+        request.META = {
+            'SERVER_NAME': 'testserver',
+            'SERVER_PORT': 80,
+        }
+        request.path = request.path_info = "/agenda/index/"
+        return request
+
+    def _get_request_cache(self):
+        request = HttpRequest()
+        request.META = {
+            'SERVER_NAME': 'testserver',
+            'SERVER_PORT': 80,
+        }
+        request.path = request.path_info = "/agenda/index/"
+        request._cache_update_cache = True
+        request.method = 'GET'
+        request.session = {}
+        return request
+
+
+
+    def test_cache_key_i18n(self):
+        settings.USE_I18N = True
+        request = self._get_request()
+        lang = translation.get_language()
+        response = HttpResponse()
+        key = cache.learn_cache_key(request, response)
+        self.assertTrue(key.endswith(lang), "Keys does not use the language")
+        key2 = cache.get_cache_key(request)        
+        self.assertEqual(key, key2)
+
+    def test_cache_key_not_i18n (self):
+        settings.USE_I18N = False
+        request = self._get_request()
+        lang = translation.get_language()
+        response = HttpResponse()
+        key = cache.learn_cache_key(request, response)
+        self.assertFalse(key.endswith(lang), "Keys does not use the language")
+
+    def test_middleware(self):
+
+        def set_cache(request, lang, msg):
+            translation.activate(lang)
+            response = HttpResponse()
+            response.content= msg
+            return UpdateCacheMiddleware().process_response(request, response)
+
+        settings.CACHE_MIDDLEWARE_SECONDS = 60
+        settings.CACHE_MIDDLEWARE_KEY_PREFIX="test"
+        settings.CACHE_BACKEND='locmem:///'
+        settings.USE_I18N = True
+        en_message ="Hello world!"
+        es_message ="Hola mundo!"
+
+        request = self._get_request_cache()
+        set_cache(request, 'en', en_message)
+        get_cache_data = FetchFromCacheMiddleware().process_request(request)
+        # Check that we can recover the cache
+        self.assertNotEqual(get_cache_data.content, None)
+        self.assertEqual(en_message, get_cache_data.content)
+        # change the session language and set content
+        request = self._get_request_cache()
+        set_cache(request, 'es', es_message)
+        # change again the language
+        translation.activate('en')
+        # retrieve the content from cache
+        get_cache_data = FetchFromCacheMiddleware().process_request(request)
+        self.assertEqual(get_cache_data.content, en_message)
+        # change again the language
+        translation.activate('es')
+        get_cache_data = FetchFromCacheMiddleware().process_request(request)
+        self.assertEqual(get_cache_data.content, es_message)
+
+
+if __name__ == '__main__':
+    unittest.main()
Index: tests/regressiontests/cachei18n/models.py
===================================================================
--- tests/regressiontests/cachei18n/models.py	(revision 0)
+++ tests/regressiontests/cachei18n/models.py	(revision 0)
@@ -0,0 +1,18 @@
+# -*- coding: UTF-8 -*-
+__doc__ = """Defines de application model"""
+
+from django.db import models
+
+
+class Person (models.Model):
+    "Defines the model for the person entity"
+    first_name = models.CharField(max_length=30)
+    last_name = models.CharField(max_length=30)
+    phone = models.CharField(max_length=20)
+    age = models.IntegerField()
+    comments = models.TextField()
+
+    def __unicode__(self):
+        return u'%s %s' % (self.first_name, self.last_name)
+
+
Index: tests/regressiontests/cachei18n/urls.py
===================================================================
--- tests/regressiontests/cachei18n/urls.py	(revision 0)
+++ tests/regressiontests/cachei18n/urls.py	(revision 0)
@@ -0,0 +1,25 @@
+from django.conf.urls.defaults import *
+from django.conf import settings 
+from django.contrib import admin
+from django.views.generic.simple import direct_to_template
+
+admin.autodiscover()
+
+urlpatterns = patterns('',
+     # our agenda application
+     (r'^$',direct_to_template, {'template': 'index.html'}),
+     (r'^appindex/$', 'views.appindex')
+     # Administration
+     (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+     (r'^admin/(.*)', admin.site.root),
+    )
+
+
+# We're going to use the Django server in development, so we'll server
+# also the estatic content.
+if settings.DEBUG:
+	urlpatterns += patterns('',
+       (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root':'./media/'}),
+    )
+
+
Index: tests/regressiontests/cachei18n/templates/agenda/index.html
===================================================================
--- tests/regressiontests/cachei18n/templates/agenda/index.html	(revision 0)
+++ tests/regressiontests/cachei18n/templates/agenda/index.html	(revision 0)
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+	<title>agenda title</title>
+<link rel="stylesheet" type="text/css" href="/media/css/paginator.css" />
+</head>
+<body>
+	<h1>{{ content }}</h1>
+</body>
+</html>
Index: tests/regressiontests/cachei18n/templates/index.html
===================================================================
--- tests/regressiontests/cachei18n/templates/index.html	(revision 0)
+++ tests/regressiontests/cachei18n/templates/index.html	(revision 0)
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">    
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <title>test title</title>
+</head>
+<body>
+    <body>
+        <p>This is a test page for cache purposes</p>
+        <p><strong>Menu</strong></p>
+    </body>
+</html>
