From 6eb02fa9bbd6e68d57f6b5b6e7419271ca4fd0ab Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Wed, 30 Dec 2009 22:11:11 +0000 Subject: [PATCH] Fixed #12448 - Make sure format strings are handled correctly as unicode. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12028 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/views/i18n.py | 3 ++- .../views/locale/ru/LC_MESSAGES/djangojs.mo | Bin 0 -> 431 bytes .../views/locale/ru/LC_MESSAGES/djangojs.po | 20 ++++++++++++++++++ tests/regressiontests/views/tests/i18n.py | 6 ++++-- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.mo create mode 100644 tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.po diff --git a/django/views/i18n.py b/django/views/i18n.py index ddd75203a7..17f5613de5 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -6,6 +6,7 @@ from django.conf import settings 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) diff --git a/tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.mo b/tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.mo new file mode 100644 index 0000000000000000000000000000000000000000..148cba533bfe58b81654c876767e3053988250f6 GIT binary patch literal 431 zcmYL^y-ve06omtVB?AK!1B3VCk|GKvl&Ya|OGN%i(@L2 zT?MA+RPF+w=x&lL9IvtoX`=4Hb&+p*1T~3gId0ps?TGaIEwJ)zkz^FdG00qsEWclhW$|8o79ZL#wlsI9 literal 0 HcmV?d00001 diff --git a/tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.po b/tests/regressiontests/views/locale/ru/LC_MESSAGES/djangojs.po new file mode 100644 index 0000000000..a0ff0152ed --- /dev/null +++ b/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 , 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 \n" +"Language-Team: LANGUAGE \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 "перевод" \ No newline at end of file diff --git a/tests/regressiontests/views/tests/i18n.py b/tests/regressiontests/views/tests/i18n.py index ebe97ab2dc..b0fa3e3f47 100644 --- a/tests/regressiontests/views/tests/i18n.py +++ b/tests/regressiontests/views/tests/i18n.py @@ -4,6 +4,7 @@ import gettext 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 @@ class I18NTests(TestCase): 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)