From 43bf086783ca60b477b0e9e19357eebf1ecb3fd9 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 2 May 2010 19:46:31 +0000 Subject: [PATCH] Fixed #13388 - Refined changes made in r12384 in the JavaScript i18n admin view. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13069 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/i18n.py | 2 +- tests/regressiontests/admin_views/tests.py | 33 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/django/views/i18n.py b/django/views/i18n.py index 5cb59c3262..831a764a2a 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -219,7 +219,7 @@ def javascript_catalog(request, domain='djangojs', packages=None): except IOError: catalog = None if catalog is not None: - t.update(catalog._catalog) + t = catalog._catalog src = [LibHead] plural = None if '' in t: diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index abb28de38b..c676555fa7 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -2,6 +2,7 @@ import re import datetime +from django.conf import settings from django.core.files import temp as tempfile from django.test import TestCase from django.contrib.auth import admin # Register auth models with the admin. @@ -15,7 +16,7 @@ from django.forms.util import ErrorList from django.utils import formats from django.utils.cache import get_max_age from django.utils.html import escape -from django.utils.translation import get_date_formats +from django.utils.translation import get_date_formats, activate, deactivate from django.utils.encoding import iri_to_uri # local test models @@ -271,6 +272,34 @@ class AdminViewBasicTest(TestCase): response = self.client.get("/test_admin/admin/admin_views/post/") self.failUnless('icon-unknown.gif' in response.content) + def testI18NLanguageNonEnglishDefault(self): + """ + Check if the Javascript i18n view returns an empty language catalog + if the default language is non-English but the selected language + is English. See #13388 and #3594 for more details. + """ + old_language_code = settings.LANGUAGE_CODE + settings.LANGUAGE_CODE = 'fr' + activate('en-us') + response = self.client.get('/test_admin/admin/jsi18n/') + self.assertNotContains(response, 'Choisir une heure') + deactivate() + settings.LANGUAGE_CODE = old_language_code + + def testI18NLanguageNonEnglishFallback(self): + """ + Makes sure that the fallback language is still working properly + in cases where the selected language cannot be found. + """ + old_language_code = settings.LANGUAGE_CODE + settings.LANGUAGE_CODE = 'fr' + activate('none') + response = self.client.get('/test_admin/admin/jsi18n/') + self.assertContains(response, 'Choisir une heure') + deactivate() + settings.LANGUAGE_CODE = old_language_code + + class SaveAsTests(TestCase): fixtures = ['admin-views-users.xml','admin-views-person.xml'] @@ -1945,7 +1974,7 @@ class NeverCacheTests(TestCase): def testJsi18n(self): "Check the never-cache status of the Javascript i18n view" - response = self.client.get('/test_admin/jsi18n/') + response = self.client.get('/test_admin/admin/jsi18n/') self.failUnlessEqual(get_max_age(response), None)