diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-02-05 19:45:26 -0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2019-02-08 10:05:53 -0500 |
| commit | 6eb4996672ca5ccaba20e468d91a83d1cd019801 (patch) | |
| tree | 659dc13499058e3e6776033d9bc846964e7c668c /django | |
| parent | 48c17807a99f7a4341c74db19e16a37b010827c2 (diff) | |
Fixed #30165 -- Deprecated ugettext(), ugettext_lazy(), ugettext_noop(), ungettext(), and ungettext_lazy().
Diffstat (limited to 'django')
| -rw-r--r-- | django/utils/translation/__init__.py | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py index 955a038109..8f3e3396a4 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -2,9 +2,11 @@ Internationalization support. """ import re +import warnings from contextlib import ContextDecorator from django.utils.autoreload import autoreload_started, file_changed +from django.utils.deprecation import RemovedInDjango40Warning from django.utils.functional import lazy __all__ = [ @@ -72,23 +74,51 @@ def gettext_noop(message): return _trans.gettext_noop(message) -ugettext_noop = gettext_noop +def ugettext_noop(message): + """ + A legacy compatibility wrapper for Unicode handling on Python 2. + Alias of gettext_noop() since Django 2.0. + """ + warnings.warn( + 'django.utils.translation.ugettext_noop() is deprecated in favor of ' + 'django.utils.translation.gettext_noop().', + RemovedInDjango40Warning, stacklevel=2, + ) + return gettext_noop(message) def gettext(message): return _trans.gettext(message) -# An alias since Django 2.0 -ugettext = gettext +def ugettext(message): + """ + A legacy compatibility wrapper for Unicode handling on Python 2. + Alias of gettext() since Django 2.0. + """ + warnings.warn( + 'django.utils.translation.ugettext() is deprecated in favor of ' + 'django.utils.translation.gettext().', + RemovedInDjango40Warning, stacklevel=2, + ) + return gettext(message) def ngettext(singular, plural, number): return _trans.ngettext(singular, plural, number) -# An alias since Django 2.0 -ungettext = ngettext +def ungettext(singular, plural, number): + """ + A legacy compatibility wrapper for Unicode handling on Python 2. + Alias of ngettext() since Django 2.0. + """ + warnings.warn( + 'django.utils.translation.ungettext() is deprecated in favor of ' + 'django.utils.translation.ngettext().', + RemovedInDjango40Warning, stacklevel=2, + ) + return ngettext(singular, plural, number) def pgettext(context, message): @@ -99,10 +129,23 @@ def npgettext(context, singular, plural, number): return _trans.npgettext(context, singular, plural, number) -gettext_lazy = ugettext_lazy = lazy(gettext, str) +gettext_lazy = lazy(gettext, str) pgettext_lazy = lazy(pgettext, str) +def ugettext_lazy(message): + """ + A legacy compatibility wrapper for Unicode handling on Python 2. Has been + Alias of gettext_lazy since Django 2.0. + """ + warnings.warn( + 'django.utils.translation.ugettext_lazy() is deprecated in favor of ' + 'django.utils.translation.gettext_lazy().', + RemovedInDjango40Warning, stacklevel=2, + ) + return gettext_lazy(message) + + def lazy_number(func, resultclass, number=None, **kwargs): if isinstance(number, int): kwargs['number'] = number @@ -158,8 +201,17 @@ def ngettext_lazy(singular, plural, number=None): return lazy_number(ngettext, str, singular=singular, plural=plural, number=number) -# An alias since Django 2.0 -ungettext_lazy = ngettext_lazy +def ungettext_lazy(singular, plural, number=None): + """ + A legacy compatibility wrapper for Unicode handling on Python 2. + An alias of ungettext_lazy() since Django 2.0. + """ + warnings.warn( + 'django.utils.translation.ungettext_lazy() is deprecated in favor of ' + 'django.utils.translation.ngettext_lazy().', + RemovedInDjango40Warning, stacklevel=2, + ) + return ngettext_lazy(singular, plural, number) def npgettext_lazy(context, singular, plural, number=None): |
