Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #12448 - Make sure format strings are handled correctly as unic…

…ode.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12028 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6eb02fa9bbd6e68d57f6b5b6e7419271ca4fd0ab 1 parent dcdca8d
@jezdez jezdez authored
View
3  django/views/i18n.py
@@ -6,6 +6,7 @@
from django.utils import importlib
from django.utils.translation import check_for_language, activate, to_locale, get_language
from django.utils.text import javascript_quote
+from django.utils.encoding import smart_unicode
from django.utils.formats import get_format_modules
def set_language(request):
@@ -208,7 +209,7 @@ def javascript_catalog(request, domain='djangojs', packages=None):
for k, v in pdict.items():
src.append("catalog['%s'] = [%s];\n" % (javascript_quote(k), ','.join(["''"]*(v+1))))
for k, v in get_formats().items():
- src.append("catalog['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(unicode(v))))
+ src.append("catalog['%s'] = '%s';\n" % (javascript_quote(k), javascript_quote(smart_unicode(v))))
src.extend(csrc)
src.append(LibFoot)
src.append(InterPolate)
View
BIN  tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.mo
Binary file not shown
View
20 tests/regressiontests/views/locale/ru/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 16:45+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\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 is to be translated"
+msgstr "перевод"
View
6 tests/regressiontests/views/tests/i18n.py
@@ -4,6 +4,7 @@
from django.conf import settings
from django.test import TestCase
from django.utils.translation import activate
+from django.utils.text import javascript_quote
from regressiontests.views.urls import locale_dir
@@ -20,11 +21,12 @@ def test_setlang(self):
def test_jsi18n(self):
"""The javascript_catalog can be deployed with language settings"""
- for lang_code in ['es', 'fr', 'en']:
+ for lang_code in ['es', 'fr', 'en', 'ru']:
activate(lang_code)
catalog = gettext.translation('djangojs', locale_dir, [lang_code])
trans_txt = catalog.ugettext('this is to be translated')
response = self.client.get('/views/jsi18n/')
# in response content must to be a line like that:
# catalog['this is to be translated'] = 'same_that_trans_txt'
- self.assertContains(response, trans_txt, 1)
+ # javascript_quote is used to be able to check unicode strings
+ self.assertContains(response, javascript_quote(trans_txt), 1)
Please sign in to comment.
Something went wrong with that request. Please try again.