From dd52eed2fb8dd93f08f12731330fa30126f800da Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Tue, 22 May 2007 08:06:57 +0000 Subject: unicode: Made lazy translation objects work properly. Fixed #4295, #4320. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5314 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/encoding.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'django/utils/encoding.py') diff --git a/django/utils/encoding.py b/django/utils/encoding.py index 5bb23a28bf..b1eaa9b805 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -17,15 +17,16 @@ def smart_unicode(s, encoding='utf-8', errors='strict'): Returns a unicode object representing 's'. Treats bytestrings using the 'encoding' codec. """ - #if isinstance(s, Promise): - # # The input is the result of a gettext_lazy() call, or similar. It will - # # already be encoded in DEFAULT_CHARSET on evaluation and we don't want - # # to evaluate it until render time. - # # FIXME: This isn't totally consistent, because it eventually returns a - # # bytestring rather than a unicode object. It works wherever we use - # # smart_unicode() at the moment. Fixing this requires work in the - # # i18n internals. - # return s + if isinstance(s, Promise): + # The input is the result of a gettext_lazy() call. + return s + return force_unicode(s, encoding, errors) + +def force_unicode(s, encoding='utf-8', errors='strict'): + """ + Similar to smart_unicode, except that lazy instances are resolved to + strings, rather than kept as lazy objects. + """ if not isinstance(s, basestring,): if hasattr(s, '__unicode__'): s = unicode(s) -- cgit v1.3