diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
index febde40..673a783 100644
a
|
b
|
ugettext_noop = gettext_noop
|
64 | 64 | def gettext(message): |
65 | 65 | return _trans.gettext(message) |
66 | 66 | |
| 67 | ugettext = gettext |
| 68 | |
67 | 69 | def ngettext(singular, plural, number): |
68 | 70 | return _trans.ngettext(singular, plural, number) |
69 | 71 | |
70 | | def ugettext(message): |
71 | | return _trans.ugettext(message) |
72 | | |
73 | | def ungettext(singular, plural, number): |
74 | | return _trans.ungettext(singular, plural, number) |
| 72 | ungettext = ngettext |
75 | 73 | |
76 | 74 | def pgettext(context, message): |
77 | 75 | return _trans.pgettext(context, message) |
… |
… |
def pgettext(context, message):
|
79 | 77 | def npgettext(context, singular, plural, number): |
80 | 78 | return _trans.npgettext(context, singular, plural, number) |
81 | 79 | |
82 | | ngettext_lazy = lazy(ngettext, bytes) |
83 | | gettext_lazy = lazy(gettext, bytes) |
84 | | ungettext_lazy = lazy(ungettext, six.text_type) |
85 | | ugettext_lazy = lazy(ugettext, six.text_type) |
| 80 | ungettext_lazy = ngettext_lazy = lazy(ngettext, six.text_type) |
| 81 | ugettext_lazy = gettext_lazy = lazy(gettext, six.text_type) |
86 | 82 | pgettext_lazy = lazy(pgettext, six.text_type) |
87 | 83 | npgettext_lazy = lazy(npgettext, six.text_type) |
88 | 84 | |
diff --git a/django/utils/translation/trans_null.py b/django/utils/translation/trans_null.py
index 5c51468..92d1205 100644
a
|
b
|
from django.utils.encoding import force_text
|
7 | 7 | from django.utils.safestring import mark_safe, SafeData |
8 | 8 | |
9 | 9 | def ngettext(singular, plural, number): |
10 | | if number == 1: return singular |
11 | | return plural |
12 | | ngettext_lazy = ngettext |
13 | | |
14 | | def ungettext(singular, plural, number): |
15 | | return force_text(ngettext(singular, plural, number)) |
| 10 | if number == 1: return force_text(singular) |
| 11 | return force_text(plural) |
| 12 | ngettext_lazy = ungettext = ngettext |
16 | 13 | |
17 | 14 | def pgettext(context, message): |
18 | | return ugettext(message) |
| 15 | return gettext(message) |
19 | 16 | |
20 | 17 | def npgettext(context, singular, plural, number): |
21 | | return ungettext(singular, plural, number) |
| 18 | return ngettext(singular, plural, number) |
22 | 19 | |
23 | 20 | activate = lambda x: None |
24 | 21 | deactivate = deactivate_all = lambda: None |
… |
… |
TECHNICAL_ID_MAP = {
|
38 | 35 | } |
39 | 36 | |
40 | 37 | def gettext(message): |
41 | | result = TECHNICAL_ID_MAP.get(message, message) |
| 38 | result = TECHNICAL_ID_MAP.get(message, force_text(message)) |
42 | 39 | if isinstance(message, SafeData): |
43 | 40 | return mark_safe(result) |
44 | 41 | return result |
45 | 42 | |
46 | | def ugettext(message): |
47 | | return force_text(gettext(message)) |
48 | | |
49 | | gettext_noop = gettext_lazy = _ = gettext |
| 43 | gettext_noop = gettext_lazy = ugettext = _ = gettext |
50 | 44 | |
51 | 45 | def to_locale(language): |
52 | 46 | p = language.find('-') |
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 9e6eadc..afb3160 100644
a
|
b
|
def do_translate(message, translation_function):
|
259 | 259 | return result |
260 | 260 | |
261 | 261 | def gettext(message): |
262 | | return do_translate(message, 'gettext') |
263 | | |
264 | | if six.PY3: |
265 | | ugettext = gettext |
266 | | else: |
267 | | def ugettext(message): |
| 262 | if six.PY3: |
| 263 | return do_translate(message, 'gettext') |
| 264 | else: |
268 | 265 | return do_translate(message, 'ugettext') |
269 | 266 | |
| 267 | ugettext = gettext |
| 268 | |
270 | 269 | def pgettext(context, message): |
271 | 270 | result = ugettext("%s%s%s" % (context, CONTEXT_SEPARATOR, message)) |
272 | 271 | if CONTEXT_SEPARATOR in result: |
… |
… |
def do_ntranslate(singular, plural, number, translation_function):
|
296 | 295 | |
297 | 296 | def ngettext(singular, plural, number): |
298 | 297 | """ |
299 | | Returns a UTF-8 bytestring of the translation of either the singular or |
| 298 | Returns a unicode string of the translation of either the singular or |
300 | 299 | plural, based on the number. |
301 | 300 | """ |
302 | | return do_ntranslate(singular, plural, number, 'ngettext') |
303 | | |
304 | | if six.PY3: |
305 | | ungettext = ngettext |
306 | | else: |
307 | | def ungettext(singular, plural, number): |
308 | | """ |
309 | | Returns a unicode strings of the translation of either the singular or |
310 | | plural, based on the number. |
311 | | """ |
| 301 | if six.PY3: |
| 302 | return do_ntranslate(singular, plural, number, 'ngettext') |
| 303 | else: |
312 | 304 | return do_ntranslate(singular, plural, number, 'ungettext') |
313 | 305 | |
| 306 | ungettext = ngettext |
| 307 | |
314 | 308 | def npgettext(context, singular, plural, number): |
315 | 309 | result = ungettext("%s%s%s" % (context, CONTEXT_SEPARATOR, singular), |
316 | 310 | "%s%s%s" % (context, CONTEXT_SEPARATOR, plural), |
diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt
index 97643c2..6c3e99d 100644
a
|
b
|
For a complete discussion on the usage of the following see the
|
595 | 595 | :doc:`translation documentation </topics/i18n/translation>`. |
596 | 596 | |
597 | 597 | .. function:: gettext(message) |
598 | | |
599 | | Translates ``message`` and returns it in a UTF-8 bytestring |
600 | | |
601 | 598 | .. function:: ugettext(message) |
602 | 599 | |
603 | 600 | Translates ``message`` and returns it in a unicode string |
604 | 601 | |
| 602 | .. versionchanged:: 1.5 |
| 603 | |
| 604 | ``gettext`` used to return an UTF8-encoded string. Both ``gettext`` and |
| 605 | ``ugettext`` return now Unicode. |
| 606 | |
605 | 607 | .. function:: pgettext(context, message) |
606 | 608 | |
607 | 609 | Translates ``message`` given the ``context`` and returns |