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
This commit is contained in:
Jannis Leidel 2009-12-30 22:11:11 +00:00
parent dcdca8d78c
commit 6eb02fa9bb
4 changed files with 26 additions and 3 deletions

View File

@ -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)

View File

@ -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 File

@ -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)