Author: mtredinnick
Date: 2007-11-17 06:11:54 -0600 (Sat, 17 Nov 2007)
New Revision: 6681

Modified:
   django/trunk/django/utils/translation/trans_null.py
   django/trunk/django/utils/translation/trans_real.py
   django/trunk/tests/regressiontests/i18n/tests.py
Log:
Translating safe strings should return a safe result.


Modified: django/trunk/django/utils/translation/trans_null.py
===================================================================
--- django/trunk/django/utils/translation/trans_null.py 2007-11-17 12:11:26 UTC 
(rev 6680)
+++ django/trunk/django/utils/translation/trans_null.py 2007-11-17 12:11:54 UTC 
(rev 6681)
@@ -4,6 +4,7 @@
 
 from django.conf import settings
 from django.utils.encoding import force_unicode
+from django.utils.safestring import mark_safe, SafeData
 
 def ngettext(singular, plural, number):
     if number == 1: return singular
@@ -31,7 +32,10 @@
 }
 
 def gettext(message):
-    return TECHNICAL_ID_MAP.get(message, message)
+    result = TECHNICAL_ID_MAP.get(message, message)
+    if isinstance(message, SafeData):
+        return mark_safe(result)
+    return result
 
 def ugettext(message):
     return force_unicode(gettext(message))

Modified: django/trunk/django/utils/translation/trans_real.py
===================================================================
--- django/trunk/django/utils/translation/trans_real.py 2007-11-17 12:11:26 UTC 
(rev 6680)
+++ django/trunk/django/utils/translation/trans_real.py 2007-11-17 12:11:54 UTC 
(rev 6681)
@@ -8,6 +8,7 @@
 from cStringIO import StringIO
 
 from django.utils.encoding import force_unicode
+from django.utils.safestring import mark_safe, SafeData
 
 try:
     import threading
@@ -271,11 +272,15 @@
     global _default, _active
     t = _active.get(currentThread(), None)
     if t is not None:
-        return getattr(t, translation_function)(message)
-    if _default is None:
-        from django.conf import settings
-        _default = translation(settings.LANGUAGE_CODE)
-    return getattr(_default, translation_function)(message)
+        result = getattr(t, translation_function)(message)
+    else:
+        if _default is None:
+            from django.conf import settings
+            _default = translation(settings.LANGUAGE_CODE)
+        result = getattr(_default, translation_function)(message)
+    if isinstance(message, SafeData):
+        return mark_safe(result)
+    return result
 
 def gettext(message):
     return do_translate(message, 'gettext')

Modified: django/trunk/tests/regressiontests/i18n/tests.py
===================================================================
--- django/trunk/tests/regressiontests/i18n/tests.py    2007-11-17 12:11:26 UTC 
(rev 6680)
+++ django/trunk/tests/regressiontests/i18n/tests.py    2007-11-17 12:11:54 UTC 
(rev 6681)
@@ -4,7 +4,7 @@
 regressions = ur"""
 Format string interpolation should work with *_lazy objects.
 
->>> from django.utils.translation import ugettext_lazy, activate, deactivate, 
gettext_lazy
+>>> from django.utils.translation import ugettext, ugettext_lazy, activate, 
deactivate, gettext_lazy
 >>> s = ugettext_lazy('Add %(name)s')
 >>> d = {'name': 'Ringo'}
 >>> s % d
@@ -39,6 +39,18 @@
 <module 'django.utils.translation' from ...>
 >>> unicode(django.utils.translation.string_concat("dja", "ngo"))
 u'django'
+
+Translating a string requiring no auto-escaping shouldn't change the "safe"
+status.
+
+>>> from django.utils.safestring import mark_safe
+>>> s = mark_safe('Password')
+>>> type(s)
+<class 'django.utils.safestring.SafeString'>
+>>> activate('de')
+>>> type(ugettext(s))
+<class 'django.utils.safestring.SafeUnicode'>
+>>> deactivate()
 """
 
 __test__ = {


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to