Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #13514 -- Corrected the process of loading multiple javascript …

…translation catalogs. Thanks to jtiai for the report, to Ramiro Morales for working out the test case, and to Ramiro and Jannis for their help on the fix.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13250 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 21e84194b5bab63f60f5d9f39d4c5ba5b1bbb5d7 1 parent b29b0f8
@freakboy3742 freakboy3742 authored
Showing with 191 additions and 15 deletions.
  1. +4 −1 django/views/i18n.py
  2. +5 −7 tests/regressiontests/admin_views/tests.py
  3. +1 −0  tests/regressiontests/views/app1/__init__.py
  4. BIN  tests/regressiontests/views/app1/locale/fr/LC_MESSAGES/djangojs.mo
  5. +20 −0 tests/regressiontests/views/app1/locale/fr/LC_MESSAGES/djangojs.po
  6. +1 −0  tests/regressiontests/views/app2/__init__.py
  7. BIN  tests/regressiontests/views/app2/locale/fr/LC_MESSAGES/djangojs.mo
  8. +20 −0 tests/regressiontests/views/app2/locale/fr/LC_MESSAGES/djangojs.po
  9. +1 −0  tests/regressiontests/views/app3/__init__.py
  10. BIN  tests/regressiontests/views/app3/locale/es_AR/LC_MESSAGES/djangojs.mo
  11. +20 −0 tests/regressiontests/views/app3/locale/es_AR/LC_MESSAGES/djangojs.po
  12. +1 −0  tests/regressiontests/views/app4/__init__.py
  13. BIN  tests/regressiontests/views/app4/locale/es_AR/LC_MESSAGES/djangojs.mo
  14. +20 −0 tests/regressiontests/views/app4/locale/es_AR/LC_MESSAGES/djangojs.po
  15. BIN  tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.mo
  16. +6 −2 tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.po
  17. BIN  tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.mo
  18. +6 −2 tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.po
  19. BIN  tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.mo
  20. +6 −2 tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.po
  21. +68 −1 tests/regressiontests/views/tests/i18n.py
  22. +12 −0 tests/regressiontests/views/urls.py
View
5 django/views/i18n.py
@@ -213,13 +213,16 @@ def javascript_catalog(request, domain='djangojs', packages=None):
if en_catalog_missing:
t = {}
else:
+ locale_t = {}
for path in paths:
try:
catalog = gettext_module.translation(domain, path, [locale])
except IOError:
catalog = None
if catalog is not None:
- t = catalog._catalog
+ locale_t.update(catalog._catalog)
+ if locale_t:
+ t = locale_t
src = [LibHead]
plural = None
if '' in t:
View
12 tests/regressiontests/admin_views/tests.py
@@ -4,7 +4,6 @@
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.
from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD
from django.contrib.contenttypes.models import ContentType
@@ -13,15 +12,16 @@
from django.contrib.admin.util import quote
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.forms.util import ErrorList
+from django.test import TestCase
from django.utils import formats
from django.utils.cache import get_max_age
+from django.utils.encoding import iri_to_uri
from django.utils.html import escape
from django.utils.translation import get_date_formats, activate, deactivate
-from django.utils.encoding import iri_to_uri
# local test models
from models import Article, BarAccount, CustomArticle, EmptyModel, \
- ExternalSubscriber, FooAccount, Gallery, ModelWithStringPrimaryKey, \
+ FooAccount, Gallery, ModelWithStringPrimaryKey, \
Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
Category, Post, Plot, FunkyTag
@@ -36,9 +36,11 @@ class AdminViewBasicTest(TestCase):
urlbit = 'admin'
def setUp(self):
+ self.old_language_code = settings.LANGUAGE_CODE
self.client.login(username='super', password='secret')
def tearDown(self):
+ settings.LANGUAGE_CODE = self.old_language_code
self.client.logout()
def testTrailingSlashRequired(self):
@@ -278,26 +280,22 @@ def testI18NLanguageNonEnglishDefault(self):
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):
View
1  tests/regressiontests/views/app1/__init__.py
@@ -0,0 +1 @@
+#
View
BIN  tests/regressiontests/views/app1/locale/fr/LC_MESSAGES/djangojs.mo
Binary file not shown
View
20 tests/regressiontests/views/app1/locale/fr/LC_MESSAGES/djangojs.po
@@ -0,0 +1,20 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-09-15 19:15+0200\n"
+"PO-Revision-Date: 2010-05-12 12:41-0300\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "this app1 string is to be translated"
+msgstr "il faut traduire cette chaîne de caractères de app1"
View
1  tests/regressiontests/views/app2/__init__.py
@@ -0,0 +1 @@
+#
View
BIN  tests/regressiontests/views/app2/locale/fr/LC_MESSAGES/djangojs.mo
Binary file not shown
View
20 tests/regressiontests/views/app2/locale/fr/LC_MESSAGES/djangojs.po
@@ -0,0 +1,20 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-09-15 19:15+0200\n"
+"PO-Revision-Date: 2010-05-12 22:05-0300\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "this app2 string is to be translated"
+msgstr "il faut traduire cette chaîne de caractères de app2"
View
1  tests/regressiontests/views/app3/__init__.py
@@ -0,0 +1 @@
+#
View
BIN  tests/regressiontests/views/app3/locale/es_AR/LC_MESSAGES/djangojs.mo
Binary file not shown
View
20 tests/regressiontests/views/app3/locale/es_AR/LC_MESSAGES/djangojs.po
@@ -0,0 +1,20 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-09-15 19:15+0200\n"
+"PO-Revision-Date: 2010-05-12 12:41-0300\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "il faut traduire cette chaîne de caractères de app3"
+msgstr "este texto de app3 debe ser traducido"
View
1  tests/regressiontests/views/app4/__init__.py
@@ -0,0 +1 @@
+#
View
BIN  tests/regressiontests/views/app4/locale/es_AR/LC_MESSAGES/djangojs.mo
Binary file not shown
View
20 tests/regressiontests/views/app4/locale/es_AR/LC_MESSAGES/djangojs.po
@@ -0,0 +1,20 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2007-09-15 19:15+0200\n"
+"PO-Revision-Date: 2010-05-12 12:41-0300\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "il faut traduire cette chaîne de caractères de app4"
+msgstr "este texto de app4 debe ser traducido"
View
BIN  tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.mo
Binary file not shown
View
8 tests/regressiontests/views/locale/es/LC_MESSAGES/djangojs.po
@@ -9,7 +9,7 @@ msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-09-15 16:45+0200\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"PO-Revision-Date: 2010-05-12 12:57-0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
@@ -18,4 +18,8 @@ msgstr ""
#: media/js/translate.js:1
msgid "this is to be translated"
-msgstr "esto tiene que ser traducido"
+msgstr "esto tiene que ser traducido"
+
+
+msgid "Choose a time"
+msgstr "Elige una hora"
View
BIN  tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.mo
Binary file not shown
View
8 tests/regressiontests/views/locale/fr/LC_MESSAGES/djangojs.po
@@ -9,7 +9,7 @@ msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-09-15 19:15+0200\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"PO-Revision-Date: 2010-05-12 12:41-0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
@@ -17,4 +17,8 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
msgid "this is to be translated"
-msgstr "il faut le traduire"
+msgstr "il faut le traduire"
+
+
+msgid "Choose a time"
+msgstr "Choisir une heure"
View
BIN  tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.mo
Binary file not shown
View
8 tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.po
@@ -9,7 +9,7 @@ msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-09-15 16:45+0200\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"PO-Revision-Date: 2010-05-12 12:57-0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
@@ -17,4 +17,8 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
msgid "this is to be translated"
-msgstr "перевод"
+msgstr "перевод"
+
+
+msgid "Choose a time"
+msgstr "Выберите время"
View
69 tests/regressiontests/views/tests/i18n.py
@@ -1,8 +1,9 @@
+# -*- coding:utf-8 -*-
import gettext
from django.conf import settings
from django.test import TestCase
-from django.utils.translation import activate
+from django.utils.translation import activate, deactivate
from django.utils.text import javascript_quote
from regressiontests.views.urls import locale_dir
@@ -30,6 +31,7 @@ def test_jsi18n(self):
# javascript_quote is used to be able to check unicode strings
self.assertContains(response, javascript_quote(trans_txt), 1)
+
class JsI18NTests(TestCase):
"""
Tests django views in django/views/i18n.py that need to change
@@ -66,3 +68,68 @@ def test_jsi18n_fallback_language(self):
activate('fi')
response = self.client.get('/views/jsi18n/')
self.assertContains(response, 'il faut le traduire')
+
+ 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.
+ """
+ settings.LANGUAGE_CODE = 'fr'
+ activate('en-us')
+ response = self.client.get('/views/jsi18n/')
+ self.assertNotContains(response, 'Choisir une heure')
+ deactivate()
+
+ def testI18NLanguageNonEnglishFallback(self):
+ """
+ Makes sure that the fallback language is still working properly
+ in cases where the selected language cannot be found.
+ """
+ settings.LANGUAGE_CODE = 'fr'
+ activate('none')
+ response = self.client.get('/views/jsi18n/')
+ self.assertContains(response, 'Choisir une heure')
+ deactivate()
+
+
+class JsI18NTestsMultiPackage(TestCase):
+ """
+ Tests for django views in django/views/i18n.py that need to change
+ settings.LANGUAGE_CODE and merge JS translation from several packages.
+ """
+
+ def setUp(self):
+ self.old_language_code = settings.LANGUAGE_CODE
+ self.old_installed_apps = settings.INSTALLED_APPS
+
+ def tearDown(self):
+ settings.LANGUAGE_CODE = self.old_language_code
+ settings.INSTALLED_APPS = self.old_installed_apps
+
+ def testI18NLanguageEnglishDefault(self):
+ """
+ Check if the JavaScript i18n view returns a complete language catalog
+ if the default language is en-us, the selected language has a
+ translation available and a catalog composed by djangojs domain
+ translations of multiple Python packages is requested. See #13388,
+ #3594 and #13514 for more details.
+ """
+ settings.LANGUAGE_CODE = 'en-us'
+ settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.views.app1', 'regressiontests.views.app2']
+ activate('fr')
+ response = self.client.get('/views/jsi18n_multi_packages1/')
+ self.assertContains(response, javascript_quote('il faut traduire cette chaîne de caractères de app1'))
+ deactivate()
+
+ def testI18NDifferentNonEnLangs(self):
+ """
+ Similar to above but with neither default or requested language being
+ English.
+ """
+ settings.LANGUAGE_CODE = 'fr'
+ settings.INSTALLED_APPS = list(settings.INSTALLED_APPS) + ['regressiontests.views.app3', 'regressiontests.views.app4']
+ activate('es-ar')
+ response = self.client.get('/views/jsi18n_multi_packages2/')
+ self.assertContains(response, javascript_quote('este texto de app3 debe ser traducido'))
+ deactivate()
View
12 tests/regressiontests/views/urls.py
@@ -16,6 +16,16 @@
'packages': ('regressiontests.views',),
}
+js_info_dict_multi_packages1 = {
+ 'domain': 'djangojs',
+ 'packages': ('regressiontests.views.app1', 'regressiontests.views.app2'),
+}
+
+js_info_dict_multi_packages2 = {
+ 'domain': 'djangojs',
+ 'packages': ('regressiontests.views.app3', 'regressiontests.views.app4'),
+}
+
date_based_info_dict = {
'queryset': Article.objects.all(),
'date_field': 'date_created',
@@ -36,6 +46,8 @@
# i18n views
(r'^i18n/', include('django.conf.urls.i18n')),
(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
+ (r'^jsi18n_multi_packages1/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages1),
+ (r'^jsi18n_multi_packages2/$', 'django.views.i18n.javascript_catalog', js_info_dict_multi_packages2),
# Static views
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': media_dir}),
Please sign in to comment.
Something went wrong with that request. Please try again.