summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2017-01-26 20:56:34 +0100
committerClaude Paroz <claude@2xlibre.net>2017-01-28 12:01:30 +0100
commite34f4e6f8735a6ad102fda096aa99cbb5600761e (patch)
tree100d6376c40d0da163b0c4ae3ad613ffd371f48b /docs
parent9e9e73735e9aa651b5c8ad7a700f90ccb5d3b18b (diff)
Made ugettext* functions aliases of gettext*
Thanks Tim Graham for the review.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/utils.txt15
-rw-r--r--docs/topics/i18n/translation.txt24
2 files changed, 12 insertions, 27 deletions
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
index 7acf057e08..cd5bbee707 100644
--- a/docs/ref/utils.txt
+++ b/docs/ref/utils.txt
@@ -1011,10 +1011,11 @@ appropriate entities.
For a complete discussion on the usage of the following see the
:doc:`translation documentation </topics/i18n/translation>`.
-.. function:: gettext(message)
-
- Translates ``message`` and returns it in a UTF-8 bytestring.
+The ``u`` prefix on the functions below comes from a difference in Python 2
+between unicode and bytestrings. If your code doesn't support Python 2, use the
+functions without the ``u``.
+.. function:: gettext(message)
.. function:: ugettext(message)
Translates ``message`` and returns it as a string.
@@ -1042,19 +1043,15 @@ For a complete discussion on the usage of the following see the
later.
.. function:: ngettext(singular, plural, number)
-
- Translates ``singular`` and ``plural`` and returns the appropriate string
- based on ``number`` in a UTF-8 bytestring.
-
.. function:: ungettext(singular, plural, number)
Translates ``singular`` and ``plural`` and returns the appropriate string
- based on ``number`` as a string.
+ based on ``number``.
.. function:: npgettext(context, singular, plural, number)
Translates ``singular`` and ``plural`` and returns the appropriate string
- based on ``number`` and the ``context`` as a string.
+ based on ``number`` and the ``context``.
.. function:: ngettext_lazy(singular, plural, number)
.. function:: ungettext_lazy(singular, plural, number)
diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt
index 0aa16717d9..a1aac296af 100644
--- a/docs/topics/i18n/translation.txt
+++ b/docs/topics/i18n/translation.txt
@@ -53,6 +53,12 @@ Specify a translation string by using the function
as a shorter alias, ``_``, to save typing.
.. note::
+ The ``u`` prefixing of ``gettext`` functions was originally to distinguish
+ usage between unicode strings and bytestrings on Python 2. For code that
+ supports only Python 3, they can be used interchangeably. A deprecation for
+ the prefixed functions may happen in a future Django release.
+
+.. note::
Python's standard library ``gettext`` module installs ``_()`` into the
global namespace, as an alias for ``gettext()``. In Django, we have chosen
not to follow this practice, for a couple of reasons:
@@ -428,24 +434,6 @@ strings before passing them to non-Django code::
requests.post('https://example.com/send', data={'body': str(body)})
-If you try to use a ``ugettext_lazy()`` result where a bytestring (a
-:class:`bytes` object) is expected, things won't work as expected since a
-``ugettext_lazy()`` object doesn't know how to convert itself to a bytestring.
-You can't use a string inside a bytestring, either, so this is consistent with
-normal Python behavior. For example, putting a string proxy into a string is
-fine::
-
- "Hello %s" % ugettext_lazy("people")
-
-But you can't insert a string into a bytestring and nor can you insert
-a string proxy there::
-
- b"Hello %s" % ugettext_lazy("people")
-
-If you ever see output that looks like ``"hello
-<django.utils.functional...>"``, you have tried to insert the result of
-``ugettext_lazy()`` into a bytestring. That's a bug in your code.
-
If you don't like the long ``ugettext_lazy`` name, you can just alias it as
``_`` (underscore), like so::