1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #9988 -- Added support for translation contexts. Thanks, Claude Paroz.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14450 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel
2010-11-04 10:48:27 +00:00
parent 0659391baf
commit 83aeb3c768
13 changed files with 137 additions and 4 deletions

View File

@@ -20,3 +20,20 @@ msgstr ""
#: models.py:3
msgid "Date/time"
msgstr "Datum/Zeit (LOCALE_PATHS)"
#: models.py:5
msgctxt "month name"
msgid "May"
msgstr "Mai"
#: models.py:7
msgctxt "verb"
msgid "May"
msgstr "Kann"
#: models.py:9
msgctxt "search"
msgid "%d result"
msgid_plural "%d results"
msgstr[0] "%d Resultat"
msgstr[1] "%d Resultate"

View File

@@ -11,7 +11,7 @@ from django.test import TestCase
from django.utils.formats import get_format, date_format, time_format, localize, localize_input, iter_format_modules
from django.utils.numberformat import format as nformat
from django.utils.safestring import mark_safe, SafeString, SafeUnicode
from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, to_locale
from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy, pgettext, npgettext, to_locale
from django.utils.importlib import import_module
@@ -54,6 +54,22 @@ class TranslationTests(TestCase):
s2 = pickle.loads(pickle.dumps(s1))
self.assertEqual(unicode(s2), "test")
def test_pgettext(self):
# Reset translation catalog to include other/locale/de
self.old_locale_paths = settings.LOCALE_PATHS
settings.LOCALE_PATHS += (os.path.join(os.path.dirname(os.path.abspath(__file__)), 'other', 'locale'),)
from django.utils.translation import trans_real
trans_real._active = {}
trans_real._translations = {}
activate('de')
self.assertEqual(pgettext("unexisting", "May"), u"May")
self.assertEqual(pgettext("month name", "May"), u"Mai")
self.assertEqual(pgettext("verb", "May"), u"Kann")
self.assertEqual(npgettext("search", "%d result", "%d results", 4) % 4, u"4 Resultate")
settings.LOCALE_PATHS = self.old_locale_paths
def test_string_concat(self):
"""
unicode(string_concat(...)) should not raise a TypeError - #4796

View File

@@ -22,3 +22,7 @@ msgstr "il faut le traduire"
msgid "Choose a time"
msgstr "Choisir une heure"
msgctxt "month name"
msgid "May"
msgstr "mai"

View File

@@ -30,6 +30,9 @@ class I18NTests(TestCase):
# catalog['this is to be translated'] = 'same_that_trans_txt'
# javascript_quote is used to be able to check unicode strings
self.assertContains(response, javascript_quote(trans_txt), 1)
if lang_code == 'fr':
# Message with context (msgctxt)
self.assertContains(response, "['month name\x04May'] = 'mai';", 1)
class JsI18NTests(TestCase):