Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8768 -- Clarified that ugettext_lazy() results are unicode pro…

…xies and

can't be used as bytestrings.

Still a number of markup changes to be made in this file (and in this
changeset). That's intentional for now, since I'm going to rewrite the file
later this week.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@9168 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 452ba4a8f743e9b553661f53231f224eb441c64e 1 parent fa63f16
Malcolm Tredinnick authored October 06, 2008

Showing 1 changed file with 20 additions and 1 deletion. Show diff stats Hide diff stats

  1. 21  docs/topics/i18n.txt
21  docs/topics/i18n.txt
@@ -174,7 +174,26 @@ For example, to translate a model's ``help_text``, do the following::
174 174
 
175 175
 In this example, ``ugettext_lazy()`` stores a lazy reference to the string --
176 176
 not the actual translation. The translation itself will be done when the string
177  
-is used in a string context, such as template rendering on the Django admin site.
  177
+is used in a string context, such as template rendering on the Django admin
  178
+site.
  179
+
  180
+The result of a ``ugettext_lazy()`` call can be used wherever you would use a
  181
+unicode string (an object with type ``unicode``) in Python. If you try to use
  182
+it where a bytestring (a ``str`` object) is expected, things will not work as
  183
+expected, since a ``ugettext_lazy()`` object doesn't know how to convert
  184
+itself to a bytestring.  You can't use a unicode string inside a bytestring,
  185
+either, so this is consistent with normal Python behavior. For example::
  186
+
  187
+    # This is fine: putting a unicode proxy into a unicode string.
  188
+    u"Hello %s" % ugettext_lazy("people")
  189
+
  190
+    # This will not work, since you cannot insert a unicode object
  191
+    # into a bytestring (nor can you insert our unicode proxy there)
  192
+    "Hello %s" % ugettext_lazy("people")
  193
+
  194
+If you ever see output that looks like ``"hello
  195
+<django.utils.functional...>"``, you have tried to insert the result of
  196
+``ugettext_lazy()`` into a bytestring. That's a bug in your code.
178 197
 
179 198
 If you don't like the verbose name ``ugettext_lazy``, you can just alias it as
180 199
 ``_`` (underscore), like so::

0 notes on commit 452ba4a

Please sign in to comment.
Something went wrong with that request. Please try again.