summaryrefslogtreecommitdiff
path: root/django/utils/translation
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 /django/utils/translation
parent9e9e73735e9aa651b5c8ad7a700f90ccb5d3b18b (diff)
Made ugettext* functions aliases of gettext*
Thanks Tim Graham for the review.
Diffstat (limited to 'django/utils/translation')
-rw-r--r--django/utils/translation/__init__.py19
-rw-r--r--django/utils/translation/trans_null.py27
-rw-r--r--django/utils/translation/trans_real.py24
3 files changed, 24 insertions, 46 deletions
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
index 2c508572b8..8728084f90 100644
--- a/django/utils/translation/__init__.py
+++ b/django/utils/translation/__init__.py
@@ -78,16 +78,16 @@ def gettext(message):
return _trans.gettext(message)
-def ngettext(singular, plural, number):
- return _trans.ngettext(singular, plural, number)
+# An alias since Django 2.0
+ugettext = gettext
-def ugettext(message):
- return _trans.ugettext(message)
+def ngettext(singular, plural, number):
+ return _trans.ngettext(singular, plural, number)
-def ungettext(singular, plural, number):
- return _trans.ungettext(singular, plural, number)
+# An alias since Django 2.0
+ungettext = ngettext
def pgettext(context, message):
@@ -98,8 +98,7 @@ def npgettext(context, singular, plural, number):
return _trans.npgettext(context, singular, plural, number)
-gettext_lazy = lazy(gettext, str)
-ugettext_lazy = lazy(ugettext, str)
+gettext_lazy = ugettext_lazy = lazy(gettext, str)
pgettext_lazy = lazy(pgettext, str)
@@ -148,8 +147,8 @@ def ngettext_lazy(singular, plural, number=None):
return lazy_number(ngettext, str, singular=singular, plural=plural, number=number)
-def ungettext_lazy(singular, plural, number=None):
- return lazy_number(ungettext, str, singular=singular, plural=plural, number=number)
+# An alias since Django 2.0
+ungettext_lazy = ngettext_lazy
def npgettext_lazy(context, singular, plural, number=None):
diff --git a/django/utils/translation/trans_null.py b/django/utils/translation/trans_null.py
index 21097244d3..72af147351 100644
--- a/django/utils/translation/trans_null.py
+++ b/django/utils/translation/trans_null.py
@@ -3,7 +3,13 @@
# settings.USE_I18N = False can use this module rather than trans_real.py.
from django.conf import settings
-from django.utils.encoding import force_text
+
+
+def gettext(message):
+ return message
+
+
+gettext_noop = gettext_lazy = _ = gettext
def ngettext(singular, plural, number):
@@ -15,16 +21,12 @@ def ngettext(singular, plural, number):
ngettext_lazy = ngettext
-def ungettext(singular, plural, number):
- return force_text(ngettext(singular, plural, number))
-
-
def pgettext(context, message):
- return ugettext(message)
+ return gettext(message)
def npgettext(context, singular, plural, number):
- return ungettext(singular, plural, number)
+ return ngettext(singular, plural, number)
def activate(x):
@@ -50,17 +52,6 @@ def check_for_language(x):
return True
-def gettext(message):
- return message
-
-
-def ugettext(message):
- return force_text(gettext(message))
-
-
-gettext_noop = gettext_lazy = _ = gettext
-
-
def to_locale(language):
p = language.find('-')
if p >= 0:
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index efa4a916df..73494320a0 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -297,10 +297,9 @@ def catalog():
return _default
-def do_translate(message, translation_function):
+def gettext(message):
"""
- Translates 'message' using the given 'translation_function' name -- which
- will be either gettext or ugettext. It uses the current thread to find the
+ Translate the 'message' string. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
"""
@@ -316,7 +315,7 @@ def do_translate(message, translation_function):
_default = _default or translation(settings.LANGUAGE_CODE)
translation_object = getattr(_active, "value", _default)
- result = getattr(translation_object, translation_function)(eol_message)
+ result = translation_object.gettext(eol_message)
if isinstance(message, SafeData):
return mark_safe(result)
@@ -324,17 +323,9 @@ def do_translate(message, translation_function):
return result
-def gettext(message):
- """Return a string of the translation of the message."""
- return do_translate(message, 'gettext')
-
-
-ugettext = gettext
-
-
def pgettext(context, message):
msg_with_ctxt = "%s%s%s" % (context, CONTEXT_SEPARATOR, message)
- result = ugettext(msg_with_ctxt)
+ result = gettext(msg_with_ctxt)
if CONTEXT_SEPARATOR in result:
# Translation not found
# force str, because the lazy version expects str.
@@ -371,17 +362,14 @@ def ngettext(singular, plural, number):
return do_ntranslate(singular, plural, number, 'ngettext')
-ungettext = ngettext
-
-
def npgettext(context, singular, plural, number):
msgs_with_ctxt = ("%s%s%s" % (context, CONTEXT_SEPARATOR, singular),
"%s%s%s" % (context, CONTEXT_SEPARATOR, plural),
number)
- result = ungettext(*msgs_with_ctxt)
+ result = ngettext(*msgs_with_ctxt)
if CONTEXT_SEPARATOR in result:
# Translation not found
- result = ungettext(singular, plural, number)
+ result = ngettext(singular, plural, number)
return result