mirror of https://github.com/django/django.git
Refs #30165 -- Removed ugettext(), ugettext_lazy(), ugettext_noop(), ungettext(), and ungettext_lazy() per deprecation timeline.
This commit is contained in:
parent
810f037b29
commit
52a238ddf2
|
@ -550,9 +550,6 @@ class Command(BaseCommand):
|
|||
'--keyword=gettext_noop',
|
||||
'--keyword=gettext_lazy',
|
||||
'--keyword=ngettext_lazy:1,2',
|
||||
'--keyword=ugettext_noop',
|
||||
'--keyword=ugettext_lazy',
|
||||
'--keyword=ungettext_lazy:1,2',
|
||||
'--keyword=pgettext:1c,2',
|
||||
'--keyword=npgettext:1c,2,3',
|
||||
'--keyword=pgettext_lazy:1c,2',
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
"""
|
||||
Internationalization support.
|
||||
"""
|
||||
import warnings
|
||||
from contextlib import ContextDecorator
|
||||
from decimal import ROUND_UP, Decimal
|
||||
|
||||
from django.utils.autoreload import autoreload_started, file_changed
|
||||
from django.utils.deprecation import RemovedInDjango40Warning
|
||||
from django.utils.functional import lazy
|
||||
from django.utils.regex_helper import _lazy_re_compile
|
||||
|
||||
|
@ -16,9 +14,7 @@ __all__ = [
|
|||
'get_language_info', 'get_language_bidi',
|
||||
'check_for_language', 'to_language', 'to_locale', 'templatize',
|
||||
'gettext', 'gettext_lazy', 'gettext_noop',
|
||||
'ugettext', 'ugettext_lazy', 'ugettext_noop',
|
||||
'ngettext', 'ngettext_lazy',
|
||||
'ungettext', 'ungettext_lazy',
|
||||
'pgettext', 'pgettext_lazy',
|
||||
'npgettext', 'npgettext_lazy',
|
||||
'LANGUAGE_SESSION_KEY',
|
||||
|
@ -77,53 +73,14 @@ def gettext_noop(message):
|
|||
return _trans.gettext_noop(message)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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):
|
||||
return _trans.pgettext(context, message)
|
||||
|
||||
|
@ -136,19 +93,6 @@ 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
|
||||
|
@ -204,19 +148,6 @@ 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):
|
||||
"""
|
||||
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):
|
||||
return lazy_number(npgettext, str, context=context, singular=singular, plural=plural, number=number)
|
||||
|
||||
|
|
|
@ -251,6 +251,9 @@ to remove usage of these features.
|
|||
|
||||
* ``django.utils.encoding.force_text()`` and ``smart_text()`` are removed.
|
||||
|
||||
* ``django.utils.translation.ugettext()``, ``ugettext_lazy()``,
|
||||
``ugettext_noop()``, ``ungettext()``, and ``ungettext_lazy()`` are removed.
|
||||
|
||||
See :ref:`deprecated-features-3.1` for details on these changes, including how
|
||||
to remove usage of these features.
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ from django.test import (
|
|||
RequestFactory, SimpleTestCase, TestCase, override_settings,
|
||||
)
|
||||
from django.utils import translation
|
||||
from django.utils.deprecation import RemovedInDjango40Warning
|
||||
from django.utils.formats import (
|
||||
date_format, get_format, get_format_modules, iter_format_modules, localize,
|
||||
localize_input, reset_format_cache, sanitize_separators, time_format,
|
||||
|
@ -34,8 +33,7 @@ from django.utils.translation import (
|
|||
get_language, get_language_bidi, get_language_from_request,
|
||||
get_language_info, gettext, gettext_lazy, ngettext, ngettext_lazy,
|
||||
npgettext, npgettext_lazy, pgettext, round_away_from_one, to_language,
|
||||
to_locale, trans_null, trans_real, ugettext, ugettext_lazy, ugettext_noop,
|
||||
ungettext, ungettext_lazy,
|
||||
to_locale, trans_null, trans_real,
|
||||
)
|
||||
from django.utils.translation.reloader import (
|
||||
translation_file_changed, watch_for_translation_changes,
|
||||
|
@ -69,46 +67,6 @@ def patch_formats(lang, **settings):
|
|||
|
||||
|
||||
class TranslationTests(SimpleTestCase):
|
||||
|
||||
@translation.override('de')
|
||||
def test_legacy_aliases(self):
|
||||
"""
|
||||
Pre-Django 2.0 aliases with u prefix are still available.
|
||||
"""
|
||||
msg = (
|
||||
'django.utils.translation.ugettext_noop() is deprecated in favor '
|
||||
'of django.utils.translation.gettext_noop().'
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango40Warning, msg):
|
||||
self.assertEqual(ugettext_noop("Image"), "Image")
|
||||
msg = (
|
||||
'django.utils.translation.ugettext() is deprecated in favor of '
|
||||
'django.utils.translation.gettext().'
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango40Warning, msg):
|
||||
self.assertEqual(ugettext("Image"), "Bild")
|
||||
msg = (
|
||||
'django.utils.translation.ugettext_lazy() is deprecated in favor '
|
||||
'of django.utils.translation.gettext_lazy().'
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango40Warning, msg):
|
||||
self.assertEqual(ugettext_lazy("Image"), gettext_lazy("Image"))
|
||||
msg = (
|
||||
'django.utils.translation.ungettext() is deprecated in favor of '
|
||||
'django.utils.translation.ngettext().'
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango40Warning, msg):
|
||||
self.assertEqual(ungettext("%d year", "%d years", 0) % 0, "0 Jahre")
|
||||
msg = (
|
||||
'django.utils.translation.ungettext_lazy() is deprecated in favor '
|
||||
'of django.utils.translation.ngettext_lazy().'
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango40Warning, msg):
|
||||
self.assertEqual(
|
||||
ungettext_lazy("%d year", "%d years", 0) % 0,
|
||||
ngettext_lazy("%d year", "%d years", 0) % 0,
|
||||
)
|
||||
|
||||
@translation.override('fr')
|
||||
def test_plural(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue