diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-05-22 08:06:57 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-05-22 08:06:57 +0000 |
| commit | dd52eed2fb8dd93f08f12731330fa30126f800da (patch) | |
| tree | 81cebcc8bfae2a4569d386190cba1aff99cddb21 /django/utils/encoding.py | |
| parent | c2c585f0f0785b71d2efbe6de8b95ff994e59601 (diff) | |
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
Diffstat (limited to 'django/utils/encoding.py')
| -rw-r--r-- | django/utils/encoding.py | 19 |
1 files changed, 10 insertions, 9 deletions
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) |
