diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py index 5630d1c94c..447311a47c 100644 --- a/django/contrib/admin/actions.py +++ b/django/contrib/admin/actions.py @@ -9,7 +9,7 @@ from django.core.exceptions import PermissionDenied from django.db import router from django.template.response import TemplateResponse from django.utils.encoding import force_text -from django.utils.translation import ugettext as _, ugettext_lazy +from django.utils.translation import gettext as _, gettext_lazy def delete_selected(modeladmin, request, queryset): @@ -84,4 +84,4 @@ def delete_selected(modeladmin, request, queryset): ], context) -delete_selected.short_description = ugettext_lazy("Delete selected %(verbose_name_plural)s") +delete_selected.short_description = gettext_lazy("Delete selected %(verbose_name_plural)s") diff --git a/django/contrib/admin/apps.py b/django/contrib/admin/apps.py index 6fa406cc44..df7d669ab0 100644 --- a/django/contrib/admin/apps.py +++ b/django/contrib/admin/apps.py @@ -1,7 +1,7 @@ from django.apps import AppConfig from django.contrib.admin.checks import check_admin_app, check_dependencies from django.core import checks -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class SimpleAdminConfig(AppConfig): diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py index f0d476ea36..a15bea9414 100644 --- a/django/contrib/admin/filters.py +++ b/django/contrib/admin/filters.py @@ -15,7 +15,7 @@ from django.core.exceptions import ImproperlyConfigured, ValidationError from django.db import models from django.utils import timezone from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class ListFilter: diff --git a/django/contrib/admin/forms.py b/django/contrib/admin/forms.py index 7c3d196012..b1f3bbe14d 100644 --- a/django/contrib/admin/forms.py +++ b/django/contrib/admin/forms.py @@ -1,6 +1,6 @@ from django import forms from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class AdminAuthenticationForm(AuthenticationForm): diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index bc1fb5e8bd..b30dce95d2 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -13,7 +13,7 @@ from django.template.defaultfilters import capfirst, linebreaksbr from django.utils.encoding import force_text from django.utils.html import conditional_escape, format_html from django.utils.safestring import mark_safe -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.translation import gettext, gettext_lazy as _ ACTION_CHECKBOX_NAME = '_selected_action' @@ -290,10 +290,10 @@ class InlineAdminFormSet: 'name': '#%s' % self.formset.prefix, 'options': { 'prefix': self.formset.prefix, - 'addText': ugettext('Add another %(verbose_name)s') % { + 'addText': gettext('Add another %(verbose_name)s') % { 'verbose_name': capfirst(verbose_name), }, - 'deleteText': ugettext('Remove'), + 'deleteText': gettext('Remove'), } }) diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py index 507b1d873e..ca4df1d970 100644 --- a/django/contrib/admin/models.py +++ b/django/contrib/admin/models.py @@ -8,7 +8,7 @@ from django.urls import NoReverseMatch, reverse from django.utils import timezone from django.utils.encoding import force_text from django.utils.text import get_text_list -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.translation import gettext, gettext_lazy as _ ADDITION = 1 CHANGE = 2 @@ -68,16 +68,16 @@ class LogEntry(models.Model): def __str__(self): if self.is_addition(): - return ugettext('Added "%(object)s".') % {'object': self.object_repr} + return gettext('Added "%(object)s".') % {'object': self.object_repr} elif self.is_change(): - return ugettext('Changed "%(object)s" - %(changes)s') % { + return gettext('Changed "%(object)s" - %(changes)s') % { 'object': self.object_repr, 'changes': self.get_change_message(), } elif self.is_deletion(): - return ugettext('Deleted "%(object)s."') % {'object': self.object_repr} + return gettext('Deleted "%(object)s."') % {'object': self.object_repr} - return ugettext('LogEntry Object') + return gettext('LogEntry Object') def is_addition(self): return self.action_flag == ADDITION @@ -102,29 +102,29 @@ class LogEntry(models.Model): for sub_message in change_message: if 'added' in sub_message: if sub_message['added']: - sub_message['added']['name'] = ugettext(sub_message['added']['name']) - messages.append(ugettext('Added {name} "{object}".').format(**sub_message['added'])) + sub_message['added']['name'] = gettext(sub_message['added']['name']) + messages.append(gettext('Added {name} "{object}".').format(**sub_message['added'])) else: - messages.append(ugettext('Added.')) + messages.append(gettext('Added.')) elif 'changed' in sub_message: sub_message['changed']['fields'] = get_text_list( - sub_message['changed']['fields'], ugettext('and') + sub_message['changed']['fields'], gettext('and') ) if 'name' in sub_message['changed']: - sub_message['changed']['name'] = ugettext(sub_message['changed']['name']) - messages.append(ugettext('Changed {fields} for {name} "{object}".').format( + sub_message['changed']['name'] = gettext(sub_message['changed']['name']) + messages.append(gettext('Changed {fields} for {name} "{object}".').format( **sub_message['changed'] )) else: - messages.append(ugettext('Changed {fields}.').format(**sub_message['changed'])) + messages.append(gettext('Changed {fields}.').format(**sub_message['changed'])) elif 'deleted' in sub_message: - sub_message['deleted']['name'] = ugettext(sub_message['deleted']['name']) - messages.append(ugettext('Deleted {name} "{object}".').format(**sub_message['deleted'])) + sub_message['deleted']['name'] = gettext(sub_message['deleted']['name']) + messages.append(gettext('Deleted {name} "{object}".').format(**sub_message['deleted'])) change_message = ' '.join(msg[0].upper() + msg[1:] for msg in messages) - return change_message or ugettext('No fields changed.') + return change_message or gettext('No fields changed.') else: return self.change_message diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index c9f5ff42c1..70b2ccba21 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -43,7 +43,7 @@ from django.utils.html import format_html from django.utils.http import urlencode from django.utils.safestring import mark_safe from django.utils.text import capfirst, format_lazy, get_text_list -from django.utils.translation import ugettext as _, ungettext +from django.utils.translation import gettext as _, ngettext from django.views.decorators.csrf import csrf_protect from django.views.generic import RedirectView @@ -1609,7 +1609,7 @@ class ModelAdmin(BaseModelAdmin): changecount += 1 if changecount: - msg = ungettext( + msg = ngettext( "%(count)s %(name)s was changed successfully.", "%(count)s %(name)s were changed successfully.", changecount @@ -1641,7 +1641,7 @@ class ModelAdmin(BaseModelAdmin): else: action_form = None - selection_note_all = ungettext( + selection_note_all = ngettext( '%(total_count)s selected', 'All %(total_count)s selected', cl.result_count diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index a95bdd7a2e..868c3f27f9 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -10,7 +10,7 @@ from django.http import Http404, HttpResponseRedirect from django.template.response import TemplateResponse from django.urls import NoReverseMatch, reverse from django.utils.text import capfirst -from django.utils.translation import ugettext as _, ugettext_lazy +from django.utils.translation import gettext as _, gettext_lazy from django.views.decorators.cache import never_cache from django.views.decorators.csrf import csrf_protect from django.views.i18n import JavaScriptCatalog @@ -36,13 +36,13 @@ class AdminSite: """ # Text to put at the end of each page's . - site_title = ugettext_lazy('Django site admin') + site_title = gettext_lazy('Django site admin') # Text to put in each page's <h1>. - site_header = ugettext_lazy('Django administration') + site_header = gettext_lazy('Django administration') # Text to put at the top of the admin index page. - index_title = ugettext_lazy('Site administration') + index_title = gettext_lazy('Site administration') # URL for the "View site" link at the top of each admin page. site_url = '/' diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 62bbbccbed..2fd0922c5e 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -19,7 +19,7 @@ from django.utils.encoding import force_text from django.utils.html import format_html from django.utils.safestring import mark_safe from django.utils.text import capfirst -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ register = Library() diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py index ad6736f771..80ff769846 100644 --- a/django/contrib/admin/tests.py +++ b/django/contrib/admin/tests.py @@ -2,7 +2,7 @@ from django.contrib.staticfiles.testing import StaticLiveServerTestCase from django.test import modify_settings from django.test.selenium import SeleniumTestCase from django.utils.deprecation import MiddlewareMixin -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ class CSPMiddleware(MiddlewareMixin): diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index 6fb5d31d93..9a89f4c578 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -14,9 +14,7 @@ from django.utils import formats, timezone from django.utils.encoding import force_text, smart_text from django.utils.html import format_html from django.utils.text import capfirst -from django.utils.translation import ( - override as translation_override, ungettext, -) +from django.utils.translation import ngettext, override as translation_override class FieldIsAForeignKeyColumnName(Exception): @@ -271,7 +269,7 @@ def model_ngettext(obj, n=None): obj = obj.model d = model_format_dict(obj) singular, plural = d["verbose_name"], d["verbose_name_plural"] - return ungettext(singular, plural, n or 0) + return ngettext(singular, plural, n or 0) def lookup_field(name, obj, model_admin=None): diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 931872ffb7..9fb65a2453 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -18,7 +18,7 @@ from django.db import models from django.urls import reverse from django.utils.encoding import force_text from django.utils.http import urlencode -from django.utils.translation import ugettext +from django.utils.translation import gettext # Changelist settings ALL_VAR = 'all' @@ -76,9 +76,9 @@ class ChangeList: self.queryset = self.get_queryset(request) self.get_results(request) if self.is_popup: - title = ugettext('Select %s') + title = gettext('Select %s') else: - title = ugettext('Select %s to change') + title = gettext('Select %s to change') self.title = title % force_text(self.opts.verbose_name) self.pk_attname = self.lookup_opts.pk.attname diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 32986b42e5..6adb20e39d 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -11,7 +11,7 @@ from django.utils.encoding import force_text from django.utils.html import smart_urlquote from django.utils.safestring import mark_safe from django.utils.text import Truncator -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ class FilteredSelectMultiple(forms.SelectMultiple): diff --git a/django/contrib/admindocs/apps.py b/django/contrib/admindocs/apps.py index 28ddbfb92a..1a502688f7 100644 --- a/django/contrib/admindocs/apps.py +++ b/django/contrib/admindocs/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class AdminDocsConfig(AppConfig): diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index db95a16f99..25263ec129 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -20,7 +20,7 @@ from django.utils.inspect import ( func_accepts_kwargs, func_accepts_var_args, func_has_no_args, get_func_full_args, ) -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.generic import TemplateView # Exclude methods starting with these strings from documentation diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py index e4e984fd53..2b432d75d2 100644 --- a/django/contrib/auth/admin.py +++ b/django/contrib/auth/admin.py @@ -16,7 +16,7 @@ from django.urls import reverse from django.utils.decorators import method_decorator from django.utils.encoding import force_text from django.utils.html import escape -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.translation import gettext, gettext_lazy as _ from django.views.decorators.csrf import csrf_protect from django.views.decorators.debug import sensitive_post_parameters @@ -144,7 +144,7 @@ class UserAdmin(admin.ModelAdmin): form.save() change_message = self.construct_change_message(request, form, None) self.log_change(request, user, change_message) - msg = ugettext('Password changed successfully.') + msg = gettext('Password changed successfully.') messages.success(request, msg) update_session_auth_hash(request, form.user) return HttpResponseRedirect( diff --git a/django/contrib/auth/apps.py b/django/contrib/auth/apps.py index d5590158cf..83790007d9 100644 --- a/django/contrib/auth/apps.py +++ b/django/contrib/auth/apps.py @@ -1,7 +1,7 @@ from django.apps import AppConfig from django.core import checks from django.db.models.signals import post_migrate -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .checks import check_models_permissions, check_user_model from .management import create_permissions diff --git a/django/contrib/auth/base_user.py b/django/contrib/auth/base_user.py index de33baf3d7..63f083b908 100644 --- a/django/contrib/auth/base_user.py +++ b/django/contrib/auth/base_user.py @@ -11,7 +11,7 @@ from django.contrib.auth.hashers import ( from django.db import models from django.utils.crypto import get_random_string, salted_hmac from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class BaseUserManager(models.Manager): diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 33b247b4c2..25835dad24 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -15,7 +15,7 @@ from django.template import loader from django.utils.encoding import force_bytes from django.utils.http import urlsafe_base64_encode from django.utils.text import capfirst -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.translation import gettext, gettext_lazy as _ UserModel = get_user_model() @@ -27,15 +27,15 @@ class ReadOnlyPasswordHashWidget(forms.Widget): context = super().get_context(name, value, attrs) summary = [] if not value or value.startswith(UNUSABLE_PASSWORD_PREFIX): - summary.append({'label': ugettext("No password set.")}) + summary.append({'label': gettext("No password set.")}) else: try: hasher = identify_hasher(value) except ValueError: - summary.append({'label': ugettext("Invalid password format or unknown hashing algorithm.")}) + summary.append({'label': gettext("Invalid password format or unknown hashing algorithm.")}) else: for key, value_ in hasher.safe_summary(value).items(): - summary.append({'label': ugettext(key), 'value': value_}) + summary.append({'label': gettext(key), 'value': value_}) context['summary'] = summary return context diff --git a/django/contrib/auth/hashers.py b/django/contrib/auth/hashers.py index fa31fa0e55..c14ece20fb 100644 --- a/django/contrib/auth/hashers.py +++ b/django/contrib/auth/hashers.py @@ -15,7 +15,7 @@ from django.utils.crypto import ( ) from django.utils.encoding import force_bytes, force_text from django.utils.module_loading import import_string -from django.utils.translation import ugettext_noop as _ +from django.utils.translation import gettext_noop as _ UNUSABLE_PASSWORD_PREFIX = '!' # This will never be a valid encoded hash UNUSABLE_PASSWORD_SUFFIX_LENGTH = 40 # number of random chars to add after UNUSABLE_PASSWORD_PREFIX diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index df4fcf4aa7..dad7d288c5 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -7,7 +7,7 @@ from django.core.mail import send_mail from django.db import models from django.db.models.manager import EmptyManager from django.utils import timezone -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .validators import UnicodeUsernameValidator diff --git a/django/contrib/auth/password_validation.py b/django/contrib/auth/password_validation.py index 23b2b6f185..aa2233e779 100644 --- a/django/contrib/auth/password_validation.py +++ b/django/contrib/auth/password_validation.py @@ -12,7 +12,7 @@ from django.utils.encoding import force_text from django.utils.functional import lazy from django.utils.html import format_html from django.utils.module_loading import import_string -from django.utils.translation import ugettext as _, ungettext +from django.utils.translation import gettext as _, ngettext @functools.lru_cache(maxsize=None) @@ -99,7 +99,7 @@ class MinimumLengthValidator: def validate(self, password, user=None): if len(password) < self.min_length: raise ValidationError( - ungettext( + ngettext( "This password is too short. It must contain at least %(min_length)d character.", "This password is too short. It must contain at least %(min_length)d characters.", self.min_length @@ -109,7 +109,7 @@ class MinimumLengthValidator: ) def get_help_text(self): - return ungettext( + return ngettext( "Your password must contain at least %(min_length)d character.", "Your password must contain at least %(min_length)d characters.", self.min_length diff --git a/django/contrib/auth/validators.py b/django/contrib/auth/validators.py index d8083de809..b4878cfd45 100644 --- a/django/contrib/auth/validators.py +++ b/django/contrib/auth/validators.py @@ -2,7 +2,7 @@ import re from django.core import validators from django.utils.deconstruct import deconstructible -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ @deconstructible diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index e629a70240..b2c37ebdb7 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -21,7 +21,7 @@ from django.utils.decorators import method_decorator from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_text from django.utils.http import is_safe_url, urlsafe_base64_decode -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.decorators.cache import never_cache from django.views.decorators.csrf import csrf_protect from django.views.decorators.debug import sensitive_post_parameters diff --git a/django/contrib/contenttypes/apps.py b/django/contrib/contenttypes/apps.py index 5754f8c24c..095dbf5615 100644 --- a/django/contrib/contenttypes/apps.py +++ b/django/contrib/contenttypes/apps.py @@ -2,7 +2,7 @@ from django.apps import AppConfig from django.contrib.contenttypes.checks import check_generic_foreign_keys from django.core import checks from django.db.models.signals import post_migrate, pre_migrate -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .management import ( create_contenttypes, inject_rename_contenttypes_operations, diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py index 20347082ae..4b9bcdc3ba 100644 --- a/django/contrib/contenttypes/models.py +++ b/django/contrib/contenttypes/models.py @@ -3,7 +3,7 @@ from collections import defaultdict from django.apps import apps from django.db import models from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class ContentTypeManager(models.Manager): diff --git a/django/contrib/contenttypes/views.py b/django/contrib/contenttypes/views.py index 50c07d1109..006a450973 100644 --- a/django/contrib/contenttypes/views.py +++ b/django/contrib/contenttypes/views.py @@ -3,7 +3,7 @@ from django.apps import apps from django.contrib.contenttypes.models import ContentType from django.contrib.sites.requests import RequestSite from django.core.exceptions import ObjectDoesNotExist -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ def shortcut(request, content_type_id, object_id): diff --git a/django/contrib/flatpages/admin.py b/django/contrib/flatpages/admin.py index d8c4eae1af..ead6b52b50 100644 --- a/django/contrib/flatpages/admin.py +++ b/django/contrib/flatpages/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from django.contrib.flatpages.forms import FlatpageForm from django.contrib.flatpages.models import FlatPage -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ @admin.register(FlatPage) diff --git a/django/contrib/flatpages/apps.py b/django/contrib/flatpages/apps.py index ac966c81f5..330ee05063 100644 --- a/django/contrib/flatpages/apps.py +++ b/django/contrib/flatpages/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class FlatPagesConfig(AppConfig): diff --git a/django/contrib/flatpages/forms.py b/django/contrib/flatpages/forms.py index 3933df8e4e..d807def77d 100644 --- a/django/contrib/flatpages/forms.py +++ b/django/contrib/flatpages/forms.py @@ -1,7 +1,7 @@ from django import forms from django.conf import settings from django.contrib.flatpages.models import FlatPage -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.translation import gettext, gettext_lazy as _ class FlatpageForm(forms.ModelForm): @@ -26,14 +26,14 @@ class FlatpageForm(forms.ModelForm): url = self.cleaned_data['url'] if not url.startswith('/'): raise forms.ValidationError( - ugettext("URL is missing a leading slash."), + gettext("URL is missing a leading slash."), code='missing_leading_slash', ) if (settings.APPEND_SLASH and 'django.middleware.common.CommonMiddleware' in settings.MIDDLEWARE and not url.endswith('/')): raise forms.ValidationError( - ugettext("URL is missing a trailing slash."), + gettext("URL is missing a trailing slash."), code='missing_trailing_slash', ) return url diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py index 38cc9fd0fe..32e4fd1123 100644 --- a/django/contrib/flatpages/models.py +++ b/django/contrib/flatpages/models.py @@ -2,7 +2,7 @@ from django.contrib.sites.models import Site from django.db import models from django.urls import get_script_prefix from django.utils.encoding import iri_to_uri -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class FlatPage(models.Model): diff --git a/django/contrib/gis/apps.py b/django/contrib/gis/apps.py index 919272b064..ffbbe63273 100644 --- a/django/contrib/gis/apps.py +++ b/django/contrib/gis/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig from django.core import serializers -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class GISConfig(AppConfig): diff --git a/django/contrib/gis/db/models/fields.py b/django/contrib/gis/db/models/fields.py index f7ca59e701..f63190e9a9 100644 --- a/django/contrib/gis/db/models/fields.py +++ b/django/contrib/gis/db/models/fields.py @@ -10,7 +10,7 @@ from django.contrib.gis.geometry.backend import Geometry, GeometryException from django.core.exceptions import ImproperlyConfigured from django.db.models.expressions import Expression from django.db.models.fields import Field -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ # Local cache of the spatial_ref_sys table, which holds SRID data for each # spatial database alias. This cache exists so that the database isn't queried diff --git a/django/contrib/gis/forms/fields.py b/django/contrib/gis/forms/fields.py index 601dd806d9..afb0974415 100644 --- a/django/contrib/gis/forms/fields.py +++ b/django/contrib/gis/forms/fields.py @@ -1,6 +1,6 @@ from django import forms from django.contrib.gis.geos import GEOSException, GEOSGeometry -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .widgets import OpenLayersWidget diff --git a/django/contrib/gis/views.py b/django/contrib/gis/views.py index db0fa3d53d..35d2b6b695 100644 --- a/django/contrib/gis/views.py +++ b/django/contrib/gis/views.py @@ -1,5 +1,5 @@ from django.http import Http404 -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ def feed(request, url, feed_dict=None): diff --git a/django/contrib/humanize/apps.py b/django/contrib/humanize/apps.py index c518ee12df..c5fcbca794 100644 --- a/django/contrib/humanize/apps.py +++ b/django/contrib/humanize/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class HumanizeConfig(AppConfig): diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py index 60cbd884ba..d00f597ea8 100644 --- a/django/contrib/humanize/templatetags/humanize.py +++ b/django/contrib/humanize/templatetags/humanize.py @@ -9,7 +9,7 @@ from django.utils.encoding import force_text from django.utils.formats import number_format from django.utils.safestring import mark_safe from django.utils.timezone import is_aware, utc -from django.utils.translation import pgettext, ugettext as _, ungettext +from django.utils.translation import gettext as _, ngettext, pgettext register = template.Library() @@ -56,48 +56,48 @@ def intcomma(value, use_l10n=True): # A tuple of standard large number to their converters intword_converters = ( (6, lambda number: ( - ungettext('%(value).1f million', '%(value).1f million', number), - ungettext('%(value)s million', '%(value)s million', number), + ngettext('%(value).1f million', '%(value).1f million', number), + ngettext('%(value)s million', '%(value)s million', number), )), (9, lambda number: ( - ungettext('%(value).1f billion', '%(value).1f billion', number), - ungettext('%(value)s billion', '%(value)s billion', number), + ngettext('%(value).1f billion', '%(value).1f billion', number), + ngettext('%(value)s billion', '%(value)s billion', number), )), (12, lambda number: ( - ungettext('%(value).1f trillion', '%(value).1f trillion', number), - ungettext('%(value)s trillion', '%(value)s trillion', number), + ngettext('%(value).1f trillion', '%(value).1f trillion', number), + ngettext('%(value)s trillion', '%(value)s trillion', number), )), (15, lambda number: ( - ungettext('%(value).1f quadrillion', '%(value).1f quadrillion', number), - ungettext('%(value)s quadrillion', '%(value)s quadrillion', number), + ngettext('%(value).1f quadrillion', '%(value).1f quadrillion', number), + ngettext('%(value)s quadrillion', '%(value)s quadrillion', number), )), (18, lambda number: ( - ungettext('%(value).1f quintillion', '%(value).1f quintillion', number), - ungettext('%(value)s quintillion', '%(value)s quintillion', number), + ngettext('%(value).1f quintillion', '%(value).1f quintillion', number), + ngettext('%(value)s quintillion', '%(value)s quintillion', number), )), (21, lambda number: ( - ungettext('%(value).1f sextillion', '%(value).1f sextillion', number), - ungettext('%(value)s sextillion', '%(value)s sextillion', number), + ngettext('%(value).1f sextillion', '%(value).1f sextillion', number), + ngettext('%(value)s sextillion', '%(value)s sextillion', number), )), (24, lambda number: ( - ungettext('%(value).1f septillion', '%(value).1f septillion', number), - ungettext('%(value)s septillion', '%(value)s septillion', number), + ngettext('%(value).1f septillion', '%(value).1f septillion', number), + ngettext('%(value)s septillion', '%(value)s septillion', number), )), (27, lambda number: ( - ungettext('%(value).1f octillion', '%(value).1f octillion', number), - ungettext('%(value)s octillion', '%(value)s octillion', number), + ngettext('%(value).1f octillion', '%(value).1f octillion', number), + ngettext('%(value)s octillion', '%(value)s octillion', number), )), (30, lambda number: ( - ungettext('%(value).1f nonillion', '%(value).1f nonillion', number), - ungettext('%(value)s nonillion', '%(value)s nonillion', number), + ngettext('%(value).1f nonillion', '%(value).1f nonillion', number), + ngettext('%(value)s nonillion', '%(value)s nonillion', number), )), (33, lambda number: ( - ungettext('%(value).1f decillion', '%(value).1f decillion', number), - ungettext('%(value)s decillion', '%(value)s decillion', number), + ngettext('%(value).1f decillion', '%(value).1f decillion', number), + ngettext('%(value)s decillion', '%(value)s decillion', number), )), (100, lambda number: ( - ungettext('%(value).1f googol', '%(value).1f googol', number), - ungettext('%(value)s googol', '%(value)s googol', number), + ngettext('%(value).1f googol', '%(value).1f googol', number), + ngettext('%(value)s googol', '%(value)s googol', number), )), ) @@ -202,21 +202,21 @@ def naturaltime(value): elif delta.seconds == 0: return _('now') elif delta.seconds < 60: - return ungettext( + return ngettext( # Translators: please keep a non-breaking space (U+00A0) # between count and time unit. 'a second ago', '%(count)s seconds ago', delta.seconds ) % {'count': delta.seconds} elif delta.seconds // 60 < 60: count = delta.seconds // 60 - return ungettext( + return ngettext( # Translators: please keep a non-breaking space (U+00A0) # between count and time unit. 'a minute ago', '%(count)s minutes ago', count ) % {'count': count} else: count = delta.seconds // 60 // 60 - return ungettext( + return ngettext( # Translators: please keep a non-breaking space (U+00A0) # between count and time unit. 'an hour ago', '%(count)s hours ago', count @@ -230,21 +230,21 @@ def naturaltime(value): elif delta.seconds == 0: return _('now') elif delta.seconds < 60: - return ungettext( + return ngettext( # Translators: please keep a non-breaking space (U+00A0) # between count and time unit. 'a second from now', '%(count)s seconds from now', delta.seconds ) % {'count': delta.seconds} elif delta.seconds // 60 < 60: count = delta.seconds // 60 - return ungettext( + return ngettext( # Translators: please keep a non-breaking space (U+00A0) # between count and time unit. 'a minute from now', '%(count)s minutes from now', count ) % {'count': count} else: count = delta.seconds // 60 // 60 - return ungettext( + return ngettext( # Translators: please keep a non-breaking space (U+00A0) # between count and time unit. 'an hour from now', '%(count)s hours from now', count diff --git a/django/contrib/messages/apps.py b/django/contrib/messages/apps.py index de48c8aa4d..0ff25d3885 100644 --- a/django/contrib/messages/apps.py +++ b/django/contrib/messages/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class MessagesConfig(AppConfig): diff --git a/django/contrib/postgres/apps.py b/django/contrib/postgres/apps.py index 0eeee6332b..6ed8dc8626 100644 --- a/django/contrib/postgres/apps.py +++ b/django/contrib/postgres/apps.py @@ -2,7 +2,7 @@ from django.apps import AppConfig from django.db import connections from django.db.backends.signals import connection_created from django.db.models import CharField, TextField -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .lookups import SearchLookup, TrigramSimilar, Unaccent from .signals import register_hstore_handler diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index 15cbf5e45e..18050e9a56 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -6,7 +6,7 @@ from django.contrib.postgres.validators import ArrayMaxLengthValidator from django.core import checks, exceptions from django.db.models import Field, IntegerField, Transform from django.db.models.lookups import Exact, In -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from ..utils import prefix_validation_error from .utils import AttributeSetter diff --git a/django/contrib/postgres/fields/hstore.py b/django/contrib/postgres/fields/hstore.py index 28b7c19c7d..e0226a8d4a 100644 --- a/django/contrib/postgres/fields/hstore.py +++ b/django/contrib/postgres/fields/hstore.py @@ -5,7 +5,7 @@ from django.contrib.postgres.fields.array import ArrayField from django.core import exceptions from django.db.models import Field, TextField, Transform from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __all__ = ['HStoreField'] diff --git a/django/contrib/postgres/fields/jsonb.py b/django/contrib/postgres/fields/jsonb.py index 0bb6e7bed1..a3a3381745 100644 --- a/django/contrib/postgres/fields/jsonb.py +++ b/django/contrib/postgres/fields/jsonb.py @@ -7,7 +7,7 @@ from django.core import exceptions from django.db.models import ( Field, TextField, Transform, lookups as builtin_lookups, ) -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __all__ = ['JSONField'] diff --git a/django/contrib/postgres/forms/array.py b/django/contrib/postgres/forms/array.py index d9d864e4f2..303b46dfb2 100644 --- a/django/contrib/postgres/forms/array.py +++ b/django/contrib/postgres/forms/array.py @@ -7,7 +7,7 @@ from django.contrib.postgres.validators import ( ) from django.core.exceptions import ValidationError from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from ..utils import prefix_validation_error diff --git a/django/contrib/postgres/forms/hstore.py b/django/contrib/postgres/forms/hstore.py index 7e046ead37..984227ff71 100644 --- a/django/contrib/postgres/forms/hstore.py +++ b/django/contrib/postgres/forms/hstore.py @@ -2,7 +2,7 @@ import json from django import forms from django.core.exceptions import ValidationError -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __all__ = ['HStoreField'] diff --git a/django/contrib/postgres/forms/jsonb.py b/django/contrib/postgres/forms/jsonb.py index 28429c7172..2cb6092cb7 100644 --- a/django/contrib/postgres/forms/jsonb.py +++ b/django/contrib/postgres/forms/jsonb.py @@ -1,7 +1,7 @@ import json from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __all__ = ['JSONField'] diff --git a/django/contrib/postgres/forms/ranges.py b/django/contrib/postgres/forms/ranges.py index 5be166f7d0..d966a6e1db 100644 --- a/django/contrib/postgres/forms/ranges.py +++ b/django/contrib/postgres/forms/ranges.py @@ -3,7 +3,7 @@ from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange from django import forms from django.core import exceptions from django.forms.widgets import MultiWidget -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __all__ = ['IntegerRangeField', 'FloatRangeField', 'DateTimeRangeField', 'DateRangeField'] diff --git a/django/contrib/postgres/utils.py b/django/contrib/postgres/utils.py index a87d519477..7c3a0d5e33 100644 --- a/django/contrib/postgres/utils.py +++ b/django/contrib/postgres/utils.py @@ -14,7 +14,7 @@ def prefix_validation_error(error, prefix, code, params): # We can't simply concatenate messages since they might require # their associated parameters to be expressed correctly which # is not something `format_lazy` does. For example, proxied - # ungettext calls require a count parameter and are converted + # ngettext calls require a count parameter and are converted # to an empty string if they are missing it. message=format_lazy( '{}{}', diff --git a/django/contrib/postgres/validators.py b/django/contrib/postgres/validators.py index a1aef12015..9d256d8d83 100644 --- a/django/contrib/postgres/validators.py +++ b/django/contrib/postgres/validators.py @@ -6,18 +6,18 @@ from django.core.validators import ( MinValueValidator, ) from django.utils.deconstruct import deconstructible -from django.utils.translation import ugettext_lazy as _, ungettext_lazy +from django.utils.translation import gettext_lazy as _, ngettext_lazy class ArrayMaxLengthValidator(MaxLengthValidator): - message = ungettext_lazy( + message = ngettext_lazy( 'List contains %(show_value)d item, it should contain no more than %(limit_value)d.', 'List contains %(show_value)d items, it should contain no more than %(limit_value)d.', 'limit_value') class ArrayMinLengthValidator(MinLengthValidator): - message = ungettext_lazy( + message = ngettext_lazy( 'List contains %(show_value)d item, it should contain no fewer than %(limit_value)d.', 'List contains %(show_value)d items, it should contain no fewer than %(limit_value)d.', 'limit_value') diff --git a/django/contrib/redirects/apps.py b/django/contrib/redirects/apps.py index f09437ed00..cab67424e7 100644 --- a/django/contrib/redirects/apps.py +++ b/django/contrib/redirects/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class RedirectsConfig(AppConfig): diff --git a/django/contrib/redirects/models.py b/django/contrib/redirects/models.py index 7a876ec76b..819aa331dd 100644 --- a/django/contrib/redirects/models.py +++ b/django/contrib/redirects/models.py @@ -1,6 +1,6 @@ from django.contrib.sites.models import Site from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class Redirect(models.Model): diff --git a/django/contrib/sessions/apps.py b/django/contrib/sessions/apps.py index 1e75a6fff8..8b778d1109 100644 --- a/django/contrib/sessions/apps.py +++ b/django/contrib/sessions/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class SessionsConfig(AppConfig): diff --git a/django/contrib/sessions/base_session.py b/django/contrib/sessions/base_session.py index e9cdcfe1c6..1d653b5adf 100644 --- a/django/contrib/sessions/base_session.py +++ b/django/contrib/sessions/base_session.py @@ -3,7 +3,7 @@ This module allows importing AbstractBaseSession even when django.contrib.sessions is not in INSTALLED_APPS. """ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class BaseSessionManager(models.Manager): diff --git a/django/contrib/sitemaps/apps.py b/django/contrib/sitemaps/apps.py index e2abc70e24..502d6890d0 100644 --- a/django/contrib/sitemaps/apps.py +++ b/django/contrib/sitemaps/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class SiteMapsConfig(AppConfig): diff --git a/django/contrib/sites/apps.py b/django/contrib/sites/apps.py index 7d319e0199..c4598049c5 100644 --- a/django/contrib/sites/apps.py +++ b/django/contrib/sites/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig from django.db.models.signals import post_migrate -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .management import create_default_site diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py index b028342a84..19f52e4487 100644 --- a/django/contrib/sites/models.py +++ b/django/contrib/sites/models.py @@ -4,7 +4,7 @@ from django.core.exceptions import ImproperlyConfigured, ValidationError from django.db import models from django.db.models.signals import pre_delete, pre_save from django.http.request import split_domain_port -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ SITE_CACHE = {} diff --git a/django/contrib/staticfiles/apps.py b/django/contrib/staticfiles/apps.py index 65865da0d2..adf9f7e57d 100644 --- a/django/contrib/staticfiles/apps.py +++ b/django/contrib/staticfiles/apps.py @@ -1,7 +1,7 @@ from django.apps import AppConfig from django.contrib.staticfiles.checks import check_finders from django.core import checks -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class StaticFilesConfig(AppConfig): diff --git a/django/contrib/syndication/apps.py b/django/contrib/syndication/apps.py index 27bda578a4..b3f7c6cd61 100644 --- a/django/contrib/syndication/apps.py +++ b/django/contrib/syndication/apps.py @@ -1,5 +1,5 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class SyndicationConfig(AppConfig): diff --git a/django/core/paginator.py b/django/core/paginator.py index abc29b3603..e0e78bf020 100644 --- a/django/core/paginator.py +++ b/django/core/paginator.py @@ -3,7 +3,7 @@ import warnings from math import ceil from django.utils.functional import cached_property -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class UnorderedObjectListWarning(RuntimeWarning): diff --git a/django/core/validators.py b/django/core/validators.py index 365c6a7f15..44db6c00f0 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -8,7 +8,7 @@ from django.utils.deconstruct import deconstructible from django.utils.encoding import force_text from django.utils.functional import SimpleLazyObject from django.utils.ipv6 import is_valid_ipv6_address -from django.utils.translation import ugettext_lazy as _, ungettext_lazy +from django.utils.translation import gettext_lazy as _, ngettext_lazy # These values, if given to validate(), will trigger the self.required check. EMPTY_VALUES = (None, '', [], (), {}) @@ -359,7 +359,7 @@ class MinValueValidator(BaseValidator): @deconstructible class MinLengthValidator(BaseValidator): - message = ungettext_lazy( + message = ngettext_lazy( 'Ensure this value has at least %(limit_value)d character (it has %(show_value)d).', 'Ensure this value has at least %(limit_value)d characters (it has %(show_value)d).', 'limit_value') @@ -374,7 +374,7 @@ class MinLengthValidator(BaseValidator): @deconstructible class MaxLengthValidator(BaseValidator): - message = ungettext_lazy( + message = ngettext_lazy( 'Ensure this value has at most %(limit_value)d character (it has %(show_value)d).', 'Ensure this value has at most %(limit_value)d characters (it has %(show_value)d).', 'limit_value') @@ -394,17 +394,17 @@ class DecimalValidator: expected, otherwise raise ValidationError. """ messages = { - 'max_digits': ungettext_lazy( + 'max_digits': ngettext_lazy( 'Ensure that there are no more than %(max)s digit in total.', 'Ensure that there are no more than %(max)s digits in total.', 'max' ), - 'max_decimal_places': ungettext_lazy( + 'max_decimal_places': ngettext_lazy( 'Ensure that there are no more than %(max)s decimal place.', 'Ensure that there are no more than %(max)s decimal places.', 'max' ), - 'max_whole_digits': ungettext_lazy( + 'max_whole_digits': ngettext_lazy( 'Ensure that there are no more than %(max)s digit before the decimal point.', 'Ensure that there are no more than %(max)s digits before the decimal point.', 'max' diff --git a/django/db/models/base.py b/django/db/models/base.py index 2914ba2a6f..cf3c3f0584 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -29,7 +29,7 @@ from django.db.models.utils import make_model_tuple from django.utils.encoding import force_text from django.utils.functional import curry from django.utils.text import capfirst, get_text_list -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.utils.version import get_version diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 68a42f0236..527ed8e423 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -30,7 +30,7 @@ from django.utils.functional import Promise, cached_property, curry from django.utils.ipv6 import clean_ipv6_address from django.utils.itercompat import is_iterable from django.utils.text import capfirst -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __all__ = [ 'AutoField', 'BLANK_CHOICE_DASH', 'BigAutoField', 'BigIntegerField', diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index 0e9ec19e70..95249dee53 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -10,7 +10,7 @@ from django.core.validators import validate_image_file_extension from django.db.models import signals from django.db.models.fields import Field from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class FieldFile(File): diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index cf39de7287..94c4cc81b9 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -14,7 +14,7 @@ from django.db.models.query_utils import PathInfo from django.db.models.utils import make_model_tuple from django.utils.encoding import force_text from django.utils.functional import cached_property, curry -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from . import Field from .related_descriptors import ( diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index 8bed2a8a52..dc34958777 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -9,7 +9,7 @@ from django.utils.functional import cached_property from django.utils.html import conditional_escape, format_html, html_safe from django.utils.inspect import func_supports_parameter from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __all__ = ('BoundField',) diff --git a/django/forms/fields.py b/django/forms/fields.py index 13899c3ab1..9d5a8cf353 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -30,7 +30,7 @@ from django.utils.dateparse import parse_duration from django.utils.duration import duration_string from django.utils.encoding import force_text from django.utils.ipv6 import clean_ipv6_address -from django.utils.translation import ugettext_lazy as _, ungettext_lazy +from django.utils.translation import gettext_lazy as _, ngettext_lazy __all__ = ( 'Field', 'CharField', 'IntegerField', @@ -534,7 +534,7 @@ class FileField(Field): 'invalid': _("No file was submitted. Check the encoding type on the form."), 'missing': _("No file was submitted."), 'empty': _("The submitted file is empty."), - 'max_length': ungettext_lazy( + 'max_length': ngettext_lazy( 'Ensure this filename has at most %(max)d character (it has %(length)d).', 'Ensure this filename has at most %(max)d characters (it has %(length)d).', 'max'), diff --git a/django/forms/forms.py b/django/forms/forms.py index 5770f6d609..99c2f03558 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -16,7 +16,7 @@ from django.utils.encoding import force_text from django.utils.functional import cached_property from django.utils.html import conditional_escape, html_safe from django.utils.safestring import mark_safe -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from .renderers import get_default_renderer diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 4d8259c2c5..60feb618db 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -6,7 +6,7 @@ from django.forms.widgets import HiddenInput from django.utils.functional import cached_property from django.utils.html import html_safe from django.utils.safestring import mark_safe -from django.utils.translation import ugettext as _, ungettext +from django.utils.translation import gettext as _, ngettext __all__ = ('BaseFormSet', 'formset_factory', 'all_valid') @@ -341,14 +341,14 @@ class BaseFormSet: if (self.validate_max and self.total_form_count() - len(self.deleted_forms) > self.max_num) or \ self.management_form.cleaned_data[TOTAL_FORM_COUNT] > self.absolute_max: - raise ValidationError(ungettext( + raise ValidationError(ngettext( "Please submit %d or fewer forms.", "Please submit %d or fewer forms.", self.max_num) % self.max_num, code='too_many_forms', ) if (self.validate_min and self.total_form_count() - len(self.deleted_forms) - empty_forms_count < self.min_num): - raise ValidationError(ungettext( + raise ValidationError(ngettext( "Please submit %d or more forms.", "Please submit %d or more forms.", self.min_num) % self.min_num, code='too_few_forms') diff --git a/django/forms/models.py b/django/forms/models.py index 0368839415..cf4775169e 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -18,7 +18,7 @@ from django.forms.widgets import ( ) from django.utils.encoding import force_text from django.utils.text import capfirst, get_text_list -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.translation import gettext, gettext_lazy as _ __all__ = ( 'ModelForm', 'BaseModelForm', 'model_to_dict', 'fields_for_model', @@ -719,16 +719,16 @@ class BaseModelFormSet(BaseFormSet): def get_unique_error_message(self, unique_check): if len(unique_check) == 1: - return ugettext("Please correct the duplicate data for %(field)s.") % { + return gettext("Please correct the duplicate data for %(field)s.") % { "field": unique_check[0], } else: - return ugettext("Please correct the duplicate data for %(field)s, which must be unique.") % { + return gettext("Please correct the duplicate data for %(field)s, which must be unique.") % { "field": get_text_list(unique_check, _("and")), } def get_date_error_message(self, date_check): - return ugettext( + return gettext( "Please correct the duplicate data for %(field_name)s " "which must be unique for the %(lookup)s in %(date_field)s." ) % { @@ -738,7 +738,7 @@ class BaseModelFormSet(BaseFormSet): } def get_form_error(self): - return ugettext("Please correct the duplicate values below.") + return gettext("Please correct the duplicate values below.") def save_existing_objects(self, commit=True): self.changed_objects = [] diff --git a/django/forms/utils.py b/django/forms/utils.py index bda4694e4f..e096f8393e 100644 --- a/django/forms/utils.py +++ b/django/forms/utils.py @@ -6,7 +6,7 @@ from django.core.exceptions import ValidationError # backwards compatibility from django.utils import timezone from django.utils.encoding import force_text from django.utils.html import escape, format_html, format_html_join, html_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ def pretty_name(name): diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 38ed56950a..c468e7d799 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -17,7 +17,7 @@ from django.utils.encoding import force_text from django.utils.formats import get_format from django.utils.html import format_html, html_safe from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy +from django.utils.translation import gettext_lazy as _ from .renderers import get_default_renderer @@ -358,9 +358,9 @@ FILE_INPUT_CONTRADICTION = object() class ClearableFileInput(FileInput): - clear_checkbox_label = ugettext_lazy('Clear') - initial_text = ugettext_lazy('Currently') - input_text = ugettext_lazy('Change') + clear_checkbox_label = _('Clear') + initial_text = _('Currently') + input_text = _('Change') template_name = 'django/forms/widgets/clearable_file_input.html' def clear_checkbox_name(self, name): @@ -690,9 +690,9 @@ class NullBooleanSelect(Select): """ def __init__(self, attrs=None): choices = ( - ('1', ugettext_lazy('Unknown')), - ('2', ugettext_lazy('Yes')), - ('3', ugettext_lazy('No')), + ('1', _('Unknown')), + ('2', _('Yes')), + ('3', _('No')), ) super().__init__(attrs, choices) diff --git a/django/template/base.py b/django/template/base.py index 51e78635de..163ea3043d 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -65,7 +65,7 @@ from django.utils.text import ( get_text_list, smart_split, unescape_string_literal, ) from django.utils.timezone import template_localtime -from django.utils.translation import pgettext_lazy, ugettext_lazy +from django.utils.translation import gettext_lazy, pgettext_lazy from .exceptions import TemplateSyntaxError @@ -824,7 +824,7 @@ class Variable: if self.message_context: return pgettext_lazy(self.message_context, msgid) else: - return ugettext_lazy(msgid) + return gettext_lazy(msgid) return value def __repr__(self): diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 5a2413d22d..09064569eb 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -19,7 +19,7 @@ from django.utils.text import ( Truncator, normalize_newlines, phone2numeric, slugify as _slugify, wrap, ) from django.utils.timesince import timesince, timeuntil -from django.utils.translation import ugettext, ungettext +from django.utils.translation import gettext, ngettext from .base import Variable, VariableDoesNotExist from .library import Library @@ -817,7 +817,7 @@ def yesno(value, arg=None): ========== ====================== ================================== """ if arg is None: - arg = ugettext('yes,no,maybe') + arg = gettext('yes,no,maybe') bits = arg.split(',') if len(bits) < 2: return value # Invalid arg. @@ -846,7 +846,7 @@ def filesizeformat(bytes_): try: bytes_ = float(bytes_) except (TypeError, ValueError, UnicodeDecodeError): - value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} + value = ngettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} return avoid_wrapping(value) def filesize_number_format(value): @@ -863,17 +863,17 @@ def filesizeformat(bytes_): bytes_ = -bytes_ # Allow formatting of negative numbers. if bytes_ < KB: - value = ungettext("%(size)d byte", "%(size)d bytes", bytes_) % {'size': bytes_} + value = ngettext("%(size)d byte", "%(size)d bytes", bytes_) % {'size': bytes_} elif bytes_ < MB: - value = ugettext("%s KB") % filesize_number_format(bytes_ / KB) + value = gettext("%s KB") % filesize_number_format(bytes_ / KB) elif bytes_ < GB: - value = ugettext("%s MB") % filesize_number_format(bytes_ / MB) + value = gettext("%s MB") % filesize_number_format(bytes_ / MB) elif bytes_ < TB: - value = ugettext("%s GB") % filesize_number_format(bytes_ / GB) + value = gettext("%s GB") % filesize_number_format(bytes_ / GB) elif bytes_ < PB: - value = ugettext("%s TB") % filesize_number_format(bytes_ / TB) + value = gettext("%s TB") % filesize_number_format(bytes_ / TB) else: - value = ugettext("%s PB") % filesize_number_format(bytes_ / PB) + value = gettext("%s PB") % filesize_number_format(bytes_ / PB) if negative: value = "-%s" % value diff --git a/django/templatetags/i18n.py b/django/templatetags/i18n.py index 456c5071ac..8627bf4331 100644 --- a/django/templatetags/i18n.py +++ b/django/templatetags/i18n.py @@ -13,7 +13,7 @@ class GetAvailableLanguagesNode(Node): self.variable = variable def render(self, context): - context[self.variable] = [(k, translation.ugettext(v)) for k, v in settings.LANGUAGES] + context[self.variable] = [(k, translation.gettext(v)) for k, v in settings.LANGUAGES] return '' @@ -142,13 +142,13 @@ class BlockTranslateNode(Node): result = translation.npgettext(message_context, singular, plural, count) else: - result = translation.ungettext(singular, plural, count) + result = translation.ngettext(singular, plural, count) vars.extend(plural_vars) else: if message_context: result = translation.pgettext(message_context, singular) else: - result = translation.ugettext(singular) + result = translation.gettext(singular) default_value = context.template.engine.string_if_invalid def render_value(key): @@ -267,7 +267,7 @@ def language_name(lang_code): @register.filter def language_name_translated(lang_code): english_name = translation.get_language_info(lang_code)['name'] - return translation.ugettext(english_name) + return translation.gettext(english_name) @register.filter diff --git a/django/urls/resolvers.py b/django/urls/resolvers.py index e71744ead7..9b8462903e 100644 --- a/django/urls/resolvers.py +++ b/django/urls/resolvers.py @@ -114,7 +114,7 @@ class LocaleRegexProvider: """ def __init__(self, regex): # regex is either a string representing a regular expression, or a - # translatable string (using ugettext_lazy) representing a regular + # translatable string (using gettext_lazy) representing a regular # expression. self._regex = regex self._regex_dict = {} diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py index 74c4b894d3..1deee1c377 100644 --- a/django/utils/dateformat.py +++ b/django/utils/dateformat.py @@ -20,7 +20,7 @@ from django.utils.dates import ( ) from django.utils.encoding import force_text from django.utils.timezone import get_default_timezone, is_aware, is_naive -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ re_formatchars = re.compile(r'(?<!\\)([aAbBcdDeEfFgGhHiIjlLmMnNoOPrsStTUuwWyYzZ])') re_escaped = re.compile(r'\\(.)') diff --git a/django/utils/dates.py b/django/utils/dates.py index 680415fccb..3108bbd223 100644 --- a/django/utils/dates.py +++ b/django/utils/dates.py @@ -1,6 +1,6 @@ "Commonly-used date structures" -from django.utils.translation import pgettext_lazy, ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _, pgettext_lazy WEEKDAYS = { 0: _('Monday'), 1: _('Tuesday'), 2: _('Wednesday'), 3: _('Thursday'), 4: _('Friday'), diff --git a/django/utils/ipv6.py b/django/utils/ipv6.py index 4eb59e6021..81733e1613 100644 --- a/django/utils/ipv6.py +++ b/django/utils/ipv6.py @@ -1,7 +1,7 @@ import ipaddress from django.core.exceptions import ValidationError -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ def clean_ipv6_address(ip_str, unpack_ipv4=False, diff --git a/django/utils/text.py b/django/utils/text.py index 0feeda7416..2898160287 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -9,7 +9,7 @@ from django.utils.functional import ( SimpleLazyObject, keep_lazy, keep_lazy_text, lazy, ) from django.utils.safestring import SafeText, mark_safe -from django.utils.translation import pgettext, ugettext as _, ugettext_lazy +from django.utils.translation import gettext as _, gettext_lazy, pgettext @keep_lazy_text @@ -240,7 +240,7 @@ def get_valid_filename(s): @keep_lazy_text -def get_text_list(list_, last_word=ugettext_lazy('or')): +def get_text_list(list_, last_word=gettext_lazy('or')): """ >>> get_text_list(['a', 'b', 'c', 'd']) 'a, b, c or d' diff --git a/django/utils/timesince.py b/django/utils/timesince.py index f87d958f4f..4dcafa521d 100644 --- a/django/utils/timesince.py +++ b/django/utils/timesince.py @@ -3,15 +3,15 @@ import datetime from django.utils.html import avoid_wrapping from django.utils.timezone import is_aware, utc -from django.utils.translation import ugettext, ungettext_lazy +from django.utils.translation import gettext, ngettext_lazy TIMESINCE_CHUNKS = ( - (60 * 60 * 24 * 365, ungettext_lazy('%d year', '%d years')), - (60 * 60 * 24 * 30, ungettext_lazy('%d month', '%d months')), - (60 * 60 * 24 * 7, ungettext_lazy('%d week', '%d weeks')), - (60 * 60 * 24, ungettext_lazy('%d day', '%d days')), - (60 * 60, ungettext_lazy('%d hour', '%d hours')), - (60, ungettext_lazy('%d minute', '%d minutes')) + (60 * 60 * 24 * 365, ngettext_lazy('%d year', '%d years')), + (60 * 60 * 24 * 30, ngettext_lazy('%d month', '%d months')), + (60 * 60 * 24 * 7, ngettext_lazy('%d week', '%d weeks')), + (60 * 60 * 24, ngettext_lazy('%d day', '%d days')), + (60 * 60, ngettext_lazy('%d hour', '%d hours')), + (60, ngettext_lazy('%d minute', '%d minutes')) ) @@ -55,7 +55,7 @@ def timesince(d, now=None, reversed=False): since = delta.days * 24 * 60 * 60 + delta.seconds if since <= 0: # d is in the future compared to now, stop processing. - return avoid_wrapping(ugettext('0 minutes')) + return avoid_wrapping(gettext('0 minutes')) for i, (seconds, name) in enumerate(TIMESINCE_CHUNKS): count = since // seconds if count != 0: @@ -66,7 +66,7 @@ def timesince(d, now=None, reversed=False): seconds2, name2 = TIMESINCE_CHUNKS[i + 1] count2 = (since - (seconds * count)) // seconds2 if count2 != 0: - result += ugettext(', ') + avoid_wrapping(name2 % count2) + result += gettext(', ') + avoid_wrapping(name2 % count2) return result diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py index 8728084f90..dc4936a976 100644 --- a/django/utils/translation/__init__.py +++ b/django/utils/translation/__init__.py @@ -250,7 +250,7 @@ def get_language_info(lang_code): raise KeyError("Unknown language code %s and %s." % (lang_code, generic_lang_code)) if info: - info['name_translated'] = ugettext_lazy(info['name']) + info['name_translated'] = gettext_lazy(info['name']) return info diff --git a/django/views/csrf.py b/django/views/csrf.py index 5e13e529fc..6119f3b49d 100644 --- a/django/views/csrf.py +++ b/django/views/csrf.py @@ -1,7 +1,7 @@ from django.conf import settings from django.http import HttpResponseForbidden from django.template import Context, Engine, TemplateDoesNotExist, loader -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.utils.version import get_docs_version # We include the template inline since we need to be able to reliably display diff --git a/django/views/debug.py b/django/views/debug.py index c22acdc676..c7c1b20f30 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -12,7 +12,7 @@ from django.utils import timezone from django.utils.datastructures import MultiValueDict from django.utils.encoding import force_text from django.utils.module_loading import import_string -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ # Minimal Django templates engine to render the error templates # regardless of the project's TEMPLATES setting. diff --git a/django/views/generic/dates.py b/django/views/generic/dates.py index f0c50a42b3..48434d2adc 100644 --- a/django/views/generic/dates.py +++ b/django/views/generic/dates.py @@ -7,7 +7,7 @@ from django.http import Http404 from django.utils import timezone from django.utils.encoding import force_text from django.utils.functional import cached_property -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.generic.base import View from django.views.generic.detail import ( BaseDetailView, SingleObjectTemplateResponseMixin, diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py index 24b406523d..fe96005ca8 100644 --- a/django/views/generic/detail.py +++ b/django/views/generic/detail.py @@ -1,7 +1,7 @@ from django.core.exceptions import ImproperlyConfigured from django.db import models from django.http import Http404 -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.generic.base import ContextMixin, TemplateResponseMixin, View diff --git a/django/views/generic/list.py b/django/views/generic/list.py index 61320fccbe..df03c586f5 100644 --- a/django/views/generic/list.py +++ b/django/views/generic/list.py @@ -2,7 +2,7 @@ from django.core.exceptions import ImproperlyConfigured from django.core.paginator import InvalidPage, Paginator from django.db.models.query import QuerySet from django.http import Http404 -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.generic.base import ContextMixin, TemplateResponseMixin, View diff --git a/django/views/static.py b/django/views/static.py index a0f4bdab56..479c59cac6 100644 --- a/django/views/static.py +++ b/django/views/static.py @@ -15,7 +15,7 @@ from django.http import ( ) from django.template import Context, Engine, TemplateDoesNotExist, loader from django.utils.http import http_date, parse_http_date -from django.utils.translation import ugettext as _, ugettext_lazy +from django.utils.translation import gettext as _, gettext_lazy def serve(request, path, document_root=None, show_indexes=False): @@ -95,7 +95,7 @@ DEFAULT_DIRECTORY_INDEX_TEMPLATE = """ </body> </html> """ -template_translatable = ugettext_lazy("Index of %(directory)s") +template_translatable = gettext_lazy("Index of %(directory)s") def directory_index(path, fullpath): diff --git a/docs/howto/custom-model-fields.txt b/docs/howto/custom-model-fields.txt index 500cf58eaa..54a62c50db 100644 --- a/docs/howto/custom-model-fields.txt +++ b/docs/howto/custom-model-fields.txt @@ -498,7 +498,7 @@ instances:: from django.core.exceptions import ValidationError from django.db import models - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ def parse_hand(hand_string): """Takes a string of cards and splits into a full hand.""" diff --git a/docs/ref/applications.txt b/docs/ref/applications.txt index edd88ceec8..be3f554004 100644 --- a/docs/ref/applications.txt +++ b/docs/ref/applications.txt @@ -457,10 +457,10 @@ Here are some common problems that you may encounter during initialization: importing an application configuration or a models module triggers code that depends on the app registry. - For example, :func:`~django.utils.translation.ugettext()` uses the app + For example, :func:`~django.utils.translation.gettext()` uses the app registry to look up translation catalogs in applications. To translate at - import time, you need :func:`~django.utils.translation.ugettext_lazy()` - instead. (Using :func:`~django.utils.translation.ugettext()` would be a bug, + import time, you need :func:`~django.utils.translation.gettext_lazy()` + instead. (Using :func:`~django.utils.translation.gettext()` would be a bug, because the translation would happen at import time, rather than at each request depending on the active language.) diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index d858a5741d..1cc52250ec 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -860,7 +860,7 @@ subclass:: from datetime import date from django.contrib import admin - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ class DecadeBornListFilter(admin.SimpleListFilter): # Human-readable title which will be displayed in the diff --git a/docs/ref/contrib/flatpages.txt b/docs/ref/contrib/flatpages.txt index 33d408a2b8..0e801a9a71 100644 --- a/docs/ref/contrib/flatpages.txt +++ b/docs/ref/contrib/flatpages.txt @@ -186,7 +186,7 @@ registering a custom ``ModelAdmin`` for ``FlatPage``:: from django.contrib import admin from django.contrib.flatpages.admin import FlatPageAdmin from django.contrib.flatpages.models import FlatPage - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ # Define a new FlatPageAdmin class FlatPageAdmin(FlatPageAdmin): diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 5510105ccb..3077a22ef2 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -261,7 +261,7 @@ access to more than a single field:: import datetime from django.core.exceptions import ValidationError from django.db import models - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ class Article(models.Model): ... diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index e379dc19f4..2dd7e57588 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -1748,11 +1748,11 @@ to restrict language selection to a subset of the Django-provided languages. If you define a custom :setting:`LANGUAGES` setting, you can mark the language names as translation strings using the -:func:`~django.utils.translation.ugettext_lazy` function. +:func:`~django.utils.translation.gettext_lazy` function. Here's a sample settings file:: - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ LANGUAGES = [ ('de', _('German')), diff --git a/docs/ref/urls.txt b/docs/ref/urls.txt index c4ff8f7b90..d44cce80da 100644 --- a/docs/ref/urls.txt +++ b/docs/ref/urls.txt @@ -34,7 +34,7 @@ Helper function to return a URL pattern for serving files in debug mode:: ] The ``regex`` parameter should be a string or -:func:`~django.utils.translation.ugettext_lazy()` (see +:func:`~django.utils.translation.gettext_lazy()` (see :ref:`translating-urlpatterns`) that contains a regular expression compatible with Python's :py:mod:`re` module. Strings typically use raw string syntax (``r''``) so that they can contain sequences like ``\d`` without the need to diff --git a/docs/ref/validators.txt b/docs/ref/validators.txt index 635f76d1eb..50badc7222 100644 --- a/docs/ref/validators.txt +++ b/docs/ref/validators.txt @@ -16,7 +16,7 @@ different types of fields. For example, here's a validator that only allows even numbers:: from django.core.exceptions import ValidationError - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ def validate_even(value): if value % 2 != 0: diff --git a/docs/topics/auth/passwords.txt b/docs/topics/auth/passwords.txt index 9cf868ca21..a786b568bc 100644 --- a/docs/topics/auth/passwords.txt +++ b/docs/topics/auth/passwords.txt @@ -646,7 +646,7 @@ have a default value. Here's a basic example of a validator, with one optional setting:: from django.core.exceptions import ValidationError - from django.utils.translation import ugettext as _ + from django.utils.translation import gettext as _ class MinimumLengthValidator(object): def __init__(self, min_length=8): diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index e638009c8c..3ce94c1b0d 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -521,7 +521,7 @@ attributes of the inner ``Meta`` class if you want to further customize a field. For example if you wanted to customize the wording of all user facing strings for the ``name`` field:: - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ class AuthorForm(ModelForm): class Meta: diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index a1aac296af..a05490ac8d 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -49,7 +49,7 @@ Standard translation -------------------- Specify a translation string by using the function -:func:`~django.utils.translation.ugettext`. It's convention to import this +:func:`~django.utils.translation.gettext`. It's convention to import this as a shorter alias, ``_``, to save typing. .. note:: @@ -63,7 +63,7 @@ as a shorter alias, ``_``, to save typing. global namespace, as an alias for ``gettext()``. In Django, we have chosen not to follow this practice, for a couple of reasons: - 1. Sometimes, you should use :func:`~django.utils.translation.ugettext_lazy` + 1. Sometimes, you should use :func:`~django.utils.translation.gettext_lazy` as the default translation method for a particular file. Without ``_()`` in the global namespace, the developer has to think about which is the most appropriate translation function. @@ -71,7 +71,7 @@ as a shorter alias, ``_``, to save typing. 2. The underscore character (``_``) is used to represent "the previous result" in Python's interactive shell and doctest tests. Installing a global ``_()`` function causes interference. Explicitly importing - ``ugettext()`` as ``_()`` avoids this problem. + ``gettext()`` as ``_()`` avoids this problem. .. admonition:: What functions may be aliased as ``_``? @@ -80,13 +80,11 @@ as a shorter alias, ``_``, to save typing. * :func:`~django.utils.translation.gettext` * :func:`~django.utils.translation.gettext_lazy` - * :func:`~django.utils.translation.ugettext` - * :func:`~django.utils.translation.ugettext_lazy` In this example, the text ``"Welcome to my site."`` is marked as a translation string:: - from django.utils.translation import ugettext as _ + from django.utils.translation import gettext as _ from django.http import HttpResponse def my_view(request): @@ -96,11 +94,11 @@ string:: Obviously, you could code this without using the alias. This example is identical to the previous one:: - from django.utils.translation import ugettext + from django.utils.translation import gettext from django.http import HttpResponse def my_view(request): - output = ugettext("Welcome to my site.") + output = gettext("Welcome to my site.") return HttpResponse(output) Translation works on computed values. This example is identical to the previous @@ -123,7 +121,7 @@ examples, is that Django's translation-string-detecting utility, :djadmin:`django-admin makemessages <makemessages>`, won't be able to find these strings. More on :djadmin:`makemessages` later.) -The strings you pass to ``_()`` or ``ugettext()`` can take placeholders, +The strings you pass to ``_()`` or ``gettext()`` can take placeholders, specified with Python's standard named-string interpolation syntax. Example:: def my_view(request, m, d): @@ -151,7 +149,7 @@ preceding the string, e.g.:: def my_view(request): # Translators: This message appears on the home page only - output = ugettext("Welcome to my site.") + output = gettext("Welcome to my site.") The comment will then appear in the resulting ``.po`` file associated with the translatable construct located below it and should also be displayed by most @@ -173,7 +171,7 @@ more details. Marking strings as no-op ------------------------ -Use the function :func:`django.utils.translation.ugettext_noop()` to mark a +Use the function :func:`django.utils.translation.gettext_noop()` to mark a string as a translation string without translating it. The string is later translated from a variable. @@ -185,11 +183,11 @@ such as when the string is presented to the user. Pluralization ------------- -Use the function :func:`django.utils.translation.ungettext()` to specify +Use the function :func:`django.utils.translation.ngettext()` to specify pluralized messages. -``ungettext`` takes three arguments: the singular translation string, the plural -translation string and the number of objects. +``ngettext()`` takes three arguments: the singular translation string, the +plural translation string and the number of objects. This function is useful when you need your Django application to be localizable to languages where the number and complexity of `plural forms @@ -200,11 +198,11 @@ of its value.) For example:: - from django.utils.translation import ungettext + from django.utils.translation import ngettext from django.http import HttpResponse def hello_world(request, count): - page = ungettext( + page = ngettext( 'there is %(count)d object', 'there are %(count)d objects', count) % { @@ -219,7 +217,7 @@ Note that pluralization is complicated and works differently in each language. Comparing ``count`` to 1 isn't always the correct rule. This code looks sophisticated, but will produce incorrect results for some languages:: - from django.utils.translation import ungettext + from django.utils.translation import ngettext from myapp.models import Report count = Report.objects.count() @@ -228,7 +226,7 @@ sophisticated, but will produce incorrect results for some languages:: else: name = Report._meta.verbose_name_plural - text = ungettext( + text = ngettext( 'There is %(count)d %(name)s available.', 'There are %(count)d %(name)s available.', count @@ -240,7 +238,7 @@ sophisticated, but will produce incorrect results for some languages:: Don't try to implement your own singular-or-plural logic, it won't be correct. In a case like this, consider something like the following:: - text = ungettext( + text = ngettext( 'There is %(count)d %(name)s object available.', 'There are %(count)d %(name)s objects available.', count @@ -253,13 +251,13 @@ In a case like this, consider something like the following:: .. note:: - When using ``ungettext()``, make sure you use a single name for every + When using ``ngettext()``, make sure you use a single name for every extrapolated variable included in the literal. In the examples above, note how we used the ``name`` Python variable in both translation strings. This example, besides being incorrect in some languages as noted above, would fail:: - text = ungettext( + text = ngettext( 'There is %(count)d %(name)s available.', 'There are %(count)d %(plural_name)s available.', count @@ -355,7 +353,7 @@ For example, to translate the help text of the *name* field in the following model, do the following:: from django.db import models - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ class MyThing(models.Model): name = models.CharField(help_text=_('This is the help text')) @@ -387,7 +385,7 @@ relying on the fallback English-centric and somewhat naïve determination of verbose names Django performs by looking at the model's class name:: from django.db import models - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ class MyThing(models.Model): name = models.CharField(_('name'), help_text=_('This is the help text')) @@ -403,7 +401,7 @@ For model methods, you can provide translations to Django and the admin site with the ``short_description`` attribute:: from django.db import models - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ class MyThing(models.Model): kind = models.ForeignKey( @@ -420,30 +418,30 @@ with the ``short_description`` attribute:: Working with lazy translation objects ------------------------------------- -The result of a ``ugettext_lazy()`` call can be used wherever you would use a -string (a :class:`str` object) in other Django code, but it may not -work with arbitrary Python code. For example, the following won't work because -the `requests <https://pypi.python.org/pypi/requests/>`_ library doesn't handle -``ugettext_lazy`` objects:: +The result of a ``gettext_lazy()`` call can be used wherever you would use a +string (a :class:`str` object) in other Django code, but it may not work with +arbitrary Python code. For example, the following won't work because the +`requests <https://pypi.python.org/pypi/requests/>`_ library doesn't handle +``gettext_lazy`` objects:: - body = ugettext_lazy("I \u2764 Django") # (unicode :heart:) + body = gettext_lazy("I \u2764 Django") # (unicode :heart:) requests.post('https://example.com/send', data={'body': body}) -You can avoid such problems by casting ``ugettext_lazy()`` objects to text +You can avoid such problems by casting ``gettext_lazy()`` objects to text strings before passing them to non-Django code:: requests.post('https://example.com/send', data={'body': str(body)}) -If you don't like the long ``ugettext_lazy`` name, you can just alias it as +If you don't like the long ``gettext_lazy`` name, you can just alias it as ``_`` (underscore), like so:: from django.db import models - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ class MyThing(models.Model): name = models.CharField(help_text=_('This is the help text')) -Using ``ugettext_lazy()`` and ``ungettext_lazy()`` to mark strings in models +Using ``gettext_lazy()`` and ``ngettext_lazy()`` to mark strings in models and utility functions is a common operation. When you're working with these objects elsewhere in your code, you should ensure that you don't accidentally convert them to strings, because they should be converted as late as possible @@ -462,10 +460,10 @@ integer as the ``number`` argument. Then ``number`` will be looked up in the dictionary under that key during string interpolation. Here's example:: from django import forms - from django.utils.translation import ungettext_lazy + from django.utils.translation import ngettext_lazy class MyForm(forms.Form): - error_message = ungettext_lazy("You only provided %(num)d argument", + error_message = ngettext_lazy("You only provided %(num)d argument", "You only provided %(num)d arguments", 'num') def clean(self): @@ -477,7 +475,7 @@ If the string contains exactly one unnamed placeholder, you can interpolate directly with the ``number`` argument:: class MyForm(forms.Form): - error_message = ungettext_lazy( + error_message = ngettext_lazy( "You provided %d argument", "You provided %d arguments", ) @@ -499,10 +497,10 @@ that runs the ``str.format()`` method only when the result is included in a string. For example:: from django.utils.text import format_lazy - from django.utils.translation import ugettext_lazy + from django.utils.translation import gettext_lazy ... - name = ugettext_lazy('John Lennon') - instrument = ugettext_lazy('guitar') + name = gettext_lazy('John Lennon') + instrument = gettext_lazy('guitar') result = format_lazy('{name}: {instrument}', name=name, instrument=instrument) In this case, the lazy translations in ``result`` will only be converted to @@ -518,7 +516,7 @@ this function inside a lazy call yourself. For example:: from django.utils.functional import lazy from django.utils.safestring import mark_safe - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ mark_safe_lazy = lazy(mark_safe, str) @@ -580,7 +578,7 @@ require translation in the future:: <title>{% trans "myvar" noop %} Internally, inline translations use an -:func:`~django.utils.translation.ugettext` call. +:func:`~django.utils.translation.gettext` call. In case a template var (``myvar`` above) is passed to the tag, the tag will first resolve such variable to a string at run-time and then look up that @@ -690,8 +688,8 @@ A more complex example:: When you use both the pluralization feature and bind values to local variables in addition to the counter value, keep in mind that the ``blocktrans`` -construct is internally converted to an ``ungettext`` call. This means the -same :ref:`notes regarding ungettext variables ` +construct is internally converted to an ``ngettext`` call. This means the +same :ref:`notes regarding ngettext variables ` apply. Reverse URL lookups cannot be carried out within the ``blocktrans`` and should @@ -1282,7 +1280,7 @@ Django provides two mechanisms to internationalize URL patterns: the language to activate from the requested URL. * Making URL patterns themselves translatable via the - :func:`django.utils.translation.ugettext_lazy()` function. + :func:`django.utils.translation.gettext_lazy()` function. .. warning:: @@ -1373,11 +1371,11 @@ Translating URL patterns ------------------------ URL patterns can also be marked translatable using the -:func:`~django.utils.translation.ugettext_lazy` function. Example:: +:func:`~django.utils.translation.gettext_lazy` function. Example:: from django.conf.urls import include, url from django.conf.urls.i18n import i18n_patterns - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ from about import views as about_views from news import views as news_views @@ -1639,12 +1637,12 @@ That's it. Your translations are ready for use. (Byte Order Mark) so if your text editor adds such marks to the beginning of files by default then you will need to reconfigure it. -Troubleshooting: ``ugettext()`` incorrectly detects ``python-format`` in strings with percent signs +Troubleshooting: ``gettext()`` incorrectly detects ``python-format`` in strings with percent signs --------------------------------------------------------------------------------------------------- In some cases, such as strings with a percent sign followed by a space and a :ref:`string conversion type ` (e.g. -``_("10% interest")``), :func:`~django.utils.translation.ugettext` incorrectly +``_("10% interest")``), :func:`~django.utils.translation.gettext` incorrectly flags strings with ``python-format``. If you try to compile message files with incorrectly flagged strings, you'll @@ -1655,7 +1653,7 @@ unlike 'msgid'``. To workaround this, you can escape percent signs by adding a second percent sign:: - from django.utils.translation import ugettext as _ + from django.utils.translation import gettext as _ output = _("10%% interest) Or you can use ``no-python-format`` so that all percent signs are treated as @@ -1859,7 +1857,7 @@ For example:: cur_language = translation.get_language() try: translation.activate(language) - text = translation.ugettext('welcome') + text = translation.gettext('welcome') finally: translation.activate(cur_language) return text @@ -1882,7 +1880,7 @@ enter and restores it on exit. With it, the above example becomes:: def welcome_translated(language): with translation.override(language): - return translation.ugettext('welcome') + return translation.gettext('welcome') Language cookie --------------- @@ -2016,12 +2014,12 @@ Notes: * If you define a custom :setting:`LANGUAGES` setting, as explained in the previous bullet, you can mark the language names as translation strings - -- but use :func:`~django.utils.translation.ugettext_lazy` instead of - :func:`~django.utils.translation.ugettext` to avoid a circular import. + -- but use :func:`~django.utils.translation.gettext_lazy` instead of + :func:`~django.utils.translation.gettext` to avoid a circular import. Here's a sample settings file:: - from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import gettext_lazy as _ LANGUAGES = [ ('de', _('German')), diff --git a/tests/admin_utils/models.py b/tests/admin_utils/models.py index cf90421e9a..dafb24e342 100644 --- a/tests/admin_utils/models.py +++ b/tests/admin_utils/models.py @@ -1,5 +1,5 @@ from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class Site(models.Model): diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 24343ea5f5..68bcd892a1 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -17,7 +17,7 @@ from django.forms.fields import CharField, Field, IntegerField from django.test import SimpleTestCase, TestCase, override_settings from django.utils import translation from django.utils.text import capfirst -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from .models.custom_user import ( CustomUser, CustomUserWithoutIsActiveField, ExtensionUser, diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index b1b629021f..28e8c6328e 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -16,7 +16,7 @@ from django.core.management import call_command from django.core.management.base import CommandError from django.db import migrations from django.test import TestCase, override_settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .models import ( CustomUser, CustomUserNonUniqueUsername, CustomUserWithFK, Email, diff --git a/tests/basic/tests.py b/tests/basic/tests.py index 571088da40..12da117edf 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -9,7 +9,7 @@ from django.test import ( SimpleTestCase, TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature, ) -from django.utils.translation import ugettext_lazy +from django.utils.translation import gettext_lazy from .models import Article, ArticleSelectOnSave, SelfRef @@ -310,13 +310,13 @@ class ModelTest(TestCase): pub_date__year=2008).extra(select={'dashed-value': '1', 'undashedvalue': '2'}) self.assertEqual(articles[0].undashedvalue, 2) - def test_create_relation_with_ugettext_lazy(self): + def test_create_relation_with_gettext_lazy(self): """ - ugettext_lazy objects work when saving model instances + gettext_lazy objects work when saving model instances through various methods. Refs #10498. """ notlazy = 'test' - lazy = ugettext_lazy(notlazy) + lazy = gettext_lazy(notlazy) Article.objects.create(headline=lazy, pub_date=datetime.now()) article = Article.objects.get() self.assertEqual(article.headline, notlazy) diff --git a/tests/flatpages_tests/test_forms.py b/tests/flatpages_tests/test_forms.py index 228790a448..9ed678fdc2 100644 --- a/tests/flatpages_tests/test_forms.py +++ b/tests/flatpages_tests/test_forms.py @@ -99,6 +99,4 @@ class FlatpageAdminFormTests(TestCase): self.assertFalse(f.is_valid()) - self.assertEqual( - f.errors, - {'sites': [translation.ugettext('This field is required.')]}) + self.assertEqual(f.errors, {'sites': [translation.gettext('This field is required.')]}) diff --git a/tests/forms_tests/tests/test_i18n.py b/tests/forms_tests/tests/test_i18n.py index a8a2cf3846..73d5b270eb 100644 --- a/tests/forms_tests/tests/test_i18n.py +++ b/tests/forms_tests/tests/test_i18n.py @@ -3,13 +3,13 @@ from django.forms import ( ) from django.test import SimpleTestCase from django.utils import translation -from django.utils.translation import gettext_lazy, ugettext_lazy +from django.utils.translation import gettext_lazy class FormsI18nTests(SimpleTestCase): def test_lazy_labels(self): class SomeForm(Form): - username = CharField(max_length=10, label=ugettext_lazy('username')) + username = CharField(max_length=10, label=gettext_lazy('username')) f = SomeForm() self.assertHTMLEqual( @@ -34,10 +34,10 @@ class FormsI18nTests(SimpleTestCase): def test_non_ascii_label(self): class SomeForm(Form): - field_1 = CharField(max_length=10, label=ugettext_lazy('field_1')) + field_1 = CharField(max_length=10, label=gettext_lazy('field_1')) field_2 = CharField( max_length=10, - label=ugettext_lazy('field_2'), + label=gettext_lazy('field_2'), widget=TextInput(attrs={'id': 'field_2_id'}), ) diff --git a/tests/forms_tests/tests/test_utils.py b/tests/forms_tests/tests/test_utils.py index 68991319e2..a9b4d99560 100644 --- a/tests/forms_tests/tests/test_utils.py +++ b/tests/forms_tests/tests/test_utils.py @@ -4,7 +4,7 @@ from django.core.exceptions import ValidationError from django.forms.utils import ErrorDict, ErrorList, flatatt from django.test import SimpleTestCase from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy +from django.utils.translation import gettext_lazy class FormsUtilsTestCase(SimpleTestCase): @@ -66,7 +66,7 @@ class FormsUtilsTestCase(SimpleTestCase): ) # Can take a lazy string. self.assertHTMLEqual( - str(ErrorList(ValidationError(ugettext_lazy("Error.")).messages)), + str(ErrorList(ValidationError(gettext_lazy("Error.")).messages)), '
  • Error.
' ) # Can take a list. @@ -84,7 +84,7 @@ class FormsUtilsTestCase(SimpleTestCase): str(ErrorList(sorted(ValidationError([ "1. First error.", "2. Not \u03C0.", - ugettext_lazy("3. Error."), + gettext_lazy("3. Error."), { 'error_1': "4. First dict error.", 'error_2': "5. Second dict error.", diff --git a/tests/humanize_tests/tests.py b/tests/humanize_tests/tests.py index 90a5155cfb..df9ae4f35d 100644 --- a/tests/humanize_tests/tests.py +++ b/tests/humanize_tests/tests.py @@ -7,7 +7,7 @@ from django.test import SimpleTestCase, modify_settings, override_settings from django.utils import translation from django.utils.html import escape from django.utils.timezone import get_fixed_timezone, utc -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ # Mock out datetime in some tests so they don't fail occasionally when they # run too slow. Use a fixed datetime for datetime.now(). DST change in diff --git a/tests/i18n/commands/__init__.py b/tests/i18n/commands/__init__.py index 39ce6d7a17..f0a06505de 100644 --- a/tests/i18n/commands/__init__.py +++ b/tests/i18n/commands/__init__.py @@ -1,4 +1,4 @@ -from django.utils.translation import ugettext as _, ungettext +from django.utils.translation import gettext as _, ngettext # Translators: This comment should be extracted dummy1 = _("This is a translatable string.") @@ -9,7 +9,7 @@ dummy2 = _("This is another translatable string.") # This file has a literal with plural forms. When processed first, makemessages # shouldn't create a .po file with duplicate `Plural-Forms` headers number = 3 -dummy3 = ungettext("%(number)s Foo", "%(number)s Foos", number) % {'number': number} +dummy3 = ngettext("%(number)s Foo", "%(number)s Foos", number) % {'number': number} dummy4 = _('Size') diff --git a/tests/i18n/commands/code.sample b/tests/i18n/commands/code.sample index bbcb83164b..a5f1520ecb 100644 --- a/tests/i18n/commands/code.sample +++ b/tests/i18n/commands/code.sample @@ -1,4 +1,4 @@ -from django.utils.translation import ugettext +from django.utils.translation import gettext # This will generate an xgettext warning -my_string = ugettext("This string contain two placeholders: %s and %s" % ('a', 'b')) +my_string = gettext("This string contain two placeholders: %s and %s" % ('a', 'b')) diff --git a/tests/i18n/exclude/__init__.py b/tests/i18n/exclude/__init__.py index ff4b2bb2ad..18c8be6e85 100644 --- a/tests/i18n/exclude/__init__.py +++ b/tests/i18n/exclude/__init__.py @@ -3,7 +3,7 @@ # The locale directory for this app is generated automatically # by the test cases. -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ # Translators: This comment should be extracted dummy1 = _("This is a translatable string.") diff --git a/tests/i18n/models.py b/tests/i18n/models.py index 3afc0841c6..15b4de57b6 100644 --- a/tests/i18n/models.py +++ b/tests/i18n/models.py @@ -1,7 +1,7 @@ from datetime import datetime from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class TestModel(models.Model): diff --git a/tests/i18n/patterns/urls/default.py b/tests/i18n/patterns/urls/default.py index caf1a7637d..b7fc38cf89 100644 --- a/tests/i18n/patterns/urls/default.py +++ b/tests/i18n/patterns/urls/default.py @@ -1,6 +1,6 @@ from django.conf.urls import include, url from django.conf.urls.i18n import i18n_patterns -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.generic import TemplateView view = TemplateView.as_view(template_name='dummy.html') diff --git a/tests/i18n/patterns/urls/namespace.py b/tests/i18n/patterns/urls/namespace.py index 3a34c7d815..2f19640d37 100644 --- a/tests/i18n/patterns/urls/namespace.py +++ b/tests/i18n/patterns/urls/namespace.py @@ -1,5 +1,5 @@ from django.conf.urls import url -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.generic import TemplateView view = TemplateView.as_view(template_name='dummy.html') diff --git a/tests/i18n/patterns/urls/wrong.py b/tests/i18n/patterns/urls/wrong.py index a8f9410db8..99504dbb87 100644 --- a/tests/i18n/patterns/urls/wrong.py +++ b/tests/i18n/patterns/urls/wrong.py @@ -1,6 +1,6 @@ from django.conf.urls import include, url from django.conf.urls.i18n import i18n_patterns -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ urlpatterns = i18n_patterns( url(_(r'^account/'), include('i18n.patterns.urls.wrong_namespace', namespace='account')), diff --git a/tests/i18n/patterns/urls/wrong_namespace.py b/tests/i18n/patterns/urls/wrong_namespace.py index 3983cb6195..f36c1a88a2 100644 --- a/tests/i18n/patterns/urls/wrong_namespace.py +++ b/tests/i18n/patterns/urls/wrong_namespace.py @@ -1,6 +1,6 @@ from django.conf.urls import url from django.conf.urls.i18n import i18n_patterns -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.generic import TemplateView view = TemplateView.as_view(template_name='dummy.html') diff --git a/tests/i18n/project_dir/__init__.py b/tests/i18n/project_dir/__init__.py index b32b258e37..2f19eed79f 100644 --- a/tests/i18n/project_dir/__init__.py +++ b/tests/i18n/project_dir/__init__.py @@ -1,4 +1,4 @@ # Sample project used by test_extraction.CustomLayoutExtractionTests -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ string = _("This is a project-level string") diff --git a/tests/i18n/project_dir/app_no_locale/models.py b/tests/i18n/project_dir/app_no_locale/models.py index 06dfbaa5d4..00c2691bf2 100644 --- a/tests/i18n/project_dir/app_no_locale/models.py +++ b/tests/i18n/project_dir/app_no_locale/models.py @@ -1,3 +1,3 @@ -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ string = _("This app has no locale directory") diff --git a/tests/i18n/project_dir/app_with_locale/models.py b/tests/i18n/project_dir/app_with_locale/models.py index ab35d5002a..b773e95e2b 100644 --- a/tests/i18n/project_dir/app_with_locale/models.py +++ b/tests/i18n/project_dir/app_with_locale/models.py @@ -1,3 +1,3 @@ -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ string = _("This app has a locale directory") diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py index db6c813115..258ab53042 100644 --- a/tests/i18n/test_compilation.py +++ b/tests/i18n/test_compilation.py @@ -15,7 +15,7 @@ from django.core.management.utils import find_command from django.test import SimpleTestCase, override_settings from django.test.utils import captured_stderr, captured_stdout from django.utils import translation -from django.utils.translation import ugettext +from django.utils.translation import gettext from .utils import RunInTmpDirMixin, copytree @@ -167,15 +167,15 @@ class FuzzyTranslationTest(ProjectAndAppTests): with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]): call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO()) with translation.override(self.LOCALE): - self.assertEqual(ugettext('Lenin'), 'Ленин') - self.assertEqual(ugettext('Vodka'), 'Vodka') + self.assertEqual(gettext('Lenin'), 'Ленин') + self.assertEqual(gettext('Vodka'), 'Vodka') def test_fuzzy_compiling(self): with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]): call_command('compilemessages', locale=[self.LOCALE], fuzzy=True, stdout=StringIO()) with translation.override(self.LOCALE): - self.assertEqual(ugettext('Lenin'), 'Ленин') - self.assertEqual(ugettext('Vodka'), 'Водка') + self.assertEqual(gettext('Lenin'), 'Ленин') + self.assertEqual(gettext('Vodka'), 'Водка') class AppCompilationTest(ProjectAndAppTests): diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 9aa8821ef9..2f61007fff 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -23,9 +23,9 @@ from django.utils.numberformat import format as nformat from django.utils.safestring import SafeText from django.utils.translation import ( LANGUAGE_SESSION_KEY, activate, check_for_language, deactivate, - get_language, get_language_from_request, get_language_info, gettext_lazy, - npgettext, npgettext_lazy, pgettext, trans_real, ugettext, ugettext_lazy, - ungettext, ungettext_lazy, + get_language, get_language_from_request, get_language_info, gettext, + gettext_lazy, ngettext, ngettext_lazy, npgettext, npgettext_lazy, pgettext, + trans_real, ugettext, ugettext_lazy, ungettext, ungettext_lazy, ) from .forms import CompanyForm, I18nForm, SelectDateForm @@ -52,15 +52,28 @@ 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. + """ + self.assertEqual(ugettext("Image"), "Bild") + self.assertEqual(ugettext_lazy("Image"), gettext_lazy("Image")) + self.assertEqual(ungettext("%d year", "%d years", 0) % 0, "0 Jahre") + 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): """ - Test plurals with ungettext. French differs from English in that 0 is singular. + Test plurals with ngettext. French differs from English in that 0 is singular. """ - self.assertEqual(ungettext("%d year", "%d years", 0) % 0, "0 année") - self.assertEqual(ungettext("%d year", "%d years", 2) % 2, "2 années") - self.assertEqual(ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}, "0 octet") - self.assertEqual(ungettext("%(size)d byte", "%(size)d bytes", 2) % {'size': 2}, "2 octets") + self.assertEqual(ngettext("%d year", "%d years", 0) % 0, "0 année") + self.assertEqual(ngettext("%d year", "%d years", 2) % 2, "2 années") + self.assertEqual(ngettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}, "0 octet") + self.assertEqual(ngettext("%(size)d byte", "%(size)d bytes", 2) % {'size': 2}, "2 octets") def test_override(self): activate('de') @@ -119,7 +132,7 @@ class TranslationTests(SimpleTestCase): """ Format string interpolation should work with *_lazy objects. """ - s = ugettext_lazy('Add %(name)s') + s = gettext_lazy('Add %(name)s') d = {'name': 'Ringo'} self.assertEqual('Add Ringo', s % d) with translation.override('de', deactivate=True): @@ -128,26 +141,26 @@ class TranslationTests(SimpleTestCase): self.assertEqual('Dodaj Ringo', s % d) # It should be possible to compare *_lazy objects. - s1 = ugettext_lazy('Add %(name)s') + s1 = gettext_lazy('Add %(name)s') self.assertEqual(s, s1) s2 = gettext_lazy('Add %(name)s') s3 = gettext_lazy('Add %(name)s') self.assertEqual(s2, s3) self.assertEqual(s, s2) - s4 = ugettext_lazy('Some other string') + s4 = gettext_lazy('Some other string') self.assertNotEqual(s, s4) def test_lazy_pickle(self): - s1 = ugettext_lazy("test") + s1 = gettext_lazy("test") self.assertEqual(str(s1), "test") s2 = pickle.loads(pickle.dumps(s1)) self.assertEqual(str(s2), "test") @override_settings(LOCALE_PATHS=extended_locale_paths) - def test_ungettext_lazy(self): - simple_with_format = ungettext_lazy('%d good result', '%d good results') + def test_ngettext_lazy(self): + simple_with_format = ngettext_lazy('%d good result', '%d good results') simple_context_with_format = npgettext_lazy('Exclamation', '%d good result', '%d good results') - simple_without_format = ungettext_lazy('good result', 'good results') + simple_without_format = ngettext_lazy('good result', 'good results') with translation.override('de'): self.assertEqual(simple_with_format % 1, '1 gutes Resultat') self.assertEqual(simple_with_format % 4, '4 guten Resultate') @@ -156,8 +169,8 @@ class TranslationTests(SimpleTestCase): self.assertEqual(simple_without_format % 1, 'gutes Resultat') self.assertEqual(simple_without_format % 4, 'guten Resultate') - complex_nonlazy = ungettext_lazy('Hi %(name)s, %(num)d good result', 'Hi %(name)s, %(num)d good results', 4) - complex_deferred = ungettext_lazy( + complex_nonlazy = ngettext_lazy('Hi %(name)s, %(num)d good result', 'Hi %(name)s, %(num)d good results', 4) + complex_deferred = ngettext_lazy( 'Hi %(name)s, %(num)d good result', 'Hi %(name)s, %(num)d good results', 'num' ) complex_context_nonlazy = npgettext_lazy( @@ -178,12 +191,12 @@ class TranslationTests(SimpleTestCase): with self.assertRaisesMessage(KeyError, 'Your dictionary lacks key'): complex_context_deferred % {'name': 'Jim'} - def test_ungettext_lazy_bool(self): - self.assertTrue(ungettext_lazy('%d good result', '%d good results')) - self.assertFalse(ungettext_lazy('', '')) + def test_ngettext_lazy_bool(self): + self.assertTrue(ngettext_lazy('%d good result', '%d good results')) + self.assertFalse(ngettext_lazy('', '')) - def test_ungettext_lazy_pickle(self): - s1 = ungettext_lazy('%d good result', '%d good results') + def test_ngettext_lazy_pickle(self): + s1 = ngettext_lazy('%d good result', '%d good results') self.assertEqual(s1 % 1, '1 good result') self.assertEqual(s1 % 8, '8 good results') s2 = pickle.loads(pickle.dumps(s1)) @@ -991,13 +1004,13 @@ class MiscTests(SimpleTestCase): or one of its variants, the untranslated string should be returned (instead of falling back to LANGUAGE_CODE) (See #24413). """ - self.assertEqual(ugettext("Image"), "Bild") + self.assertEqual(gettext("Image"), "Bild") with translation.override('en'): - self.assertEqual(ugettext("Image"), "Image") + self.assertEqual(gettext("Image"), "Image") with translation.override('en-us'): - self.assertEqual(ugettext("Image"), "Image") + self.assertEqual(gettext("Image"), "Image") with translation.override('en-ca'): - self.assertEqual(ugettext("Image"), "Image") + self.assertEqual(gettext("Image"), "Image") def test_parse_spec_http_header(self): """ @@ -1222,8 +1235,8 @@ class ResolutionOrderI18NTests(SimpleTestCase): deactivate() super().tearDown() - def assertUgettext(self, msgid, msgstr): - result = ugettext(msgid) + def assertGettext(self, msgid, msgstr): + result = gettext(msgid) self.assertIn( msgstr, result, "The string '%s' isn't in the translation of '%s'; the actual result is '%s'." @@ -1236,7 +1249,7 @@ class AppResolutionOrderI18NTests(ResolutionOrderI18NTests): @override_settings(LANGUAGE_CODE='de') def test_app_translation(self): # Original translation. - self.assertUgettext('Date/time', 'Datum/Zeit') + self.assertGettext('Date/time', 'Datum/Zeit') # Different translation. with self.modify_settings(INSTALLED_APPS={'append': 'i18n.resolution'}): @@ -1244,31 +1257,31 @@ class AppResolutionOrderI18NTests(ResolutionOrderI18NTests): activate('de') # Doesn't work because it's added later in the list. - self.assertUgettext('Date/time', 'Datum/Zeit') + self.assertGettext('Date/time', 'Datum/Zeit') with self.modify_settings(INSTALLED_APPS={'remove': 'django.contrib.admin.apps.SimpleAdminConfig'}): # Force refreshing translations. activate('de') # Unless the original is removed from the list. - self.assertUgettext('Date/time', 'Datum/Zeit (APP)') + self.assertGettext('Date/time', 'Datum/Zeit (APP)') @override_settings(LOCALE_PATHS=extended_locale_paths) class LocalePathsResolutionOrderI18NTests(ResolutionOrderI18NTests): def test_locale_paths_translation(self): - self.assertUgettext('Time', 'LOCALE_PATHS') + self.assertGettext('Time', 'LOCALE_PATHS') def test_locale_paths_override_app_translation(self): with self.settings(INSTALLED_APPS=['i18n.resolution']): - self.assertUgettext('Time', 'LOCALE_PATHS') + self.assertGettext('Time', 'LOCALE_PATHS') class DjangoFallbackResolutionOrderI18NTests(ResolutionOrderI18NTests): def test_django_fallback(self): - self.assertEqual(ugettext('Date/time'), 'Datum/Zeit') + self.assertEqual(gettext('Date/time'), 'Datum/Zeit') class TestModels(TestCase): @@ -1296,7 +1309,7 @@ class TestLanguageInfo(SimpleTestCase): with translation.override('xx'): # A language with no translation catalogs should fallback to the # untranslated string. - self.assertEqual(ugettext("Title"), "Title") + self.assertEqual(gettext("Title"), "Title") def test_unknown_only_country_code(self): li = get_language_info('de-xx') @@ -1511,7 +1524,7 @@ class NonDjangoLanguageTests(SimpleTestCase): ) def test_non_django_language(self): self.assertEqual(get_language(), 'xxx') - self.assertEqual(ugettext("year"), "reay") + self.assertEqual(gettext("year"), "reay") @override_settings( USE_I18N=True, @@ -1524,4 +1537,4 @@ class NonDjangoLanguageTests(SimpleTestCase): @translation.override('xyz') def test_plural_non_django_language(self): self.assertEqual(get_language(), 'xyz') - self.assertEqual(ungettext('year', 'years', 2), 'years') + self.assertEqual(ngettext('year', 'years', 2), 'years') diff --git a/tests/i18n/urls.py b/tests/i18n/urls.py index 911a1cf8e7..233ad699a3 100644 --- a/tests/i18n/urls.py +++ b/tests/i18n/urls.py @@ -1,7 +1,7 @@ from django.conf.urls import url from django.conf.urls.i18n import i18n_patterns from django.http import HttpResponse, StreamingHttpResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ urlpatterns = i18n_patterns( url(r'^simple/$', lambda r: HttpResponse()), diff --git a/tests/i18n/urls_default_unprefixed.py b/tests/i18n/urls_default_unprefixed.py index 85f9bf049b..9f0e6f3902 100644 --- a/tests/i18n/urls_default_unprefixed.py +++ b/tests/i18n/urls_default_unprefixed.py @@ -1,7 +1,7 @@ from django.conf.urls import url from django.conf.urls.i18n import i18n_patterns from django.http import HttpResponse -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ urlpatterns = i18n_patterns( url(r'^(?P[\w-]+)-page', lambda request, **arg: HttpResponse(_("Yes"))), diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 242bb57915..74d40c67ce 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -26,7 +26,7 @@ from django.core.mail.message import BadHeaderError, sanitize_address from django.test import SimpleTestCase, override_settings from django.test.utils import requires_tz_support from django.utils.encoding import force_bytes, force_text -from django.utils.translation import ugettext_lazy +from django.utils.translation import gettext_lazy class HeadersCheckMixin: @@ -177,7 +177,7 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): with self.assertRaises(BadHeaderError): email.message() email = EmailMessage( - ugettext_lazy('Subject\nInjection Test'), 'Content', 'from@example.com', ['to@example.com'] + gettext_lazy('Subject\nInjection Test'), 'Content', 'from@example.com', ['to@example.com'] ) with self.assertRaises(BadHeaderError): email.message() @@ -856,12 +856,12 @@ class BaseEmailBackendTests(HeadersCheckMixin): String prefix + lazy translated subject = bad output Regression for #13494 """ - mail_managers(ugettext_lazy('Subject'), 'Content') + mail_managers(gettext_lazy('Subject'), 'Content') message = self.get_the_message() self.assertEqual(message.get('subject'), '[Django] Subject') self.flush_mailbox() - mail_admins(ugettext_lazy('Subject'), 'Content') + mail_admins(gettext_lazy('Subject'), 'Content') message = self.get_the_message() self.assertEqual(message.get('subject'), '[Django] Subject') @@ -926,7 +926,7 @@ class BaseEmailBackendTests(HeadersCheckMixin): """ Email sending should support lazy email addresses (#24416). """ - _ = ugettext_lazy + _ = gettext_lazy self.assertTrue(send_mail('Subject', 'Content', _('tester'), [_('django')])) message = self.get_the_message() self.assertEqual(message.get('from'), 'tester') diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py index 52ddcc8cfe..8252fd0e56 100644 --- a/tests/many_to_one/tests.py +++ b/tests/many_to_one/tests.py @@ -5,7 +5,7 @@ from django.core.exceptions import FieldError, MultipleObjectsReturned from django.db import models, transaction from django.db.utils import IntegrityError from django.test import TestCase -from django.utils.translation import ugettext_lazy +from django.utils.translation import gettext_lazy from .models import ( Article, Category, Child, City, District, First, Parent, Record, Relation, @@ -429,9 +429,9 @@ class ManyToOneTests(TestCase): # Same as each other self.assertIs(r1.article_set.__class__, r2.article_set.__class__) - def test_create_relation_with_ugettext_lazy(self): + def test_create_relation_with_gettext_lazy(self): reporter = Reporter.objects.create(first_name='John', last_name='Smith', email='john.smith@example.com') - lazy = ugettext_lazy('test') + lazy = gettext_lazy('test') reporter.article_set.create(headline=lazy, pub_date=datetime.date(2011, 6, 10)) notlazy = str(lazy) article = reporter.article_set.get() diff --git a/tests/messages_tests/base.py b/tests/messages_tests/base.py index f713d72ab8..d05f73bb82 100644 --- a/tests/messages_tests/base.py +++ b/tests/messages_tests/base.py @@ -6,7 +6,7 @@ from django.contrib.messages.storage import base, default_storage from django.contrib.messages.storage.base import Message from django.test import modify_settings, override_settings from django.urls import reverse -from django.utils.translation import ugettext_lazy +from django.utils.translation import gettext_lazy def add_level_messages(storage): @@ -100,7 +100,7 @@ class BaseTests: storage = self.get_storage() response = self.get_response() - storage.add(constants.INFO, ugettext_lazy('lazy message')) + storage.add(constants.INFO, gettext_lazy('lazy message')) storage.update(response) storing = self.stored_messages_count(storage, response) diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 32751d8923..1e6455d2fa 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -24,7 +24,7 @@ from django.utils import datetime_safe from django.utils.deconstruct import deconstructible from django.utils.functional import SimpleLazyObject from django.utils.timezone import FixedOffset, get_default_timezone, utc -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .models import FoodManager, FoodQuerySet diff --git a/tests/queryset_pickle/models.py b/tests/queryset_pickle/models.py index a5c0d15441..fba65d7a9e 100644 --- a/tests/queryset_pickle/models.py +++ b/tests/queryset_pickle/models.py @@ -1,7 +1,7 @@ import datetime from django.db import DJANGO_VERSION_PICKLE_KEY, models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ def standalone_number(): diff --git a/tests/serializers/test_json.py b/tests/serializers/test_json.py index ae671f4847..9037e75e46 100644 --- a/tests/serializers/test_json.py +++ b/tests/serializers/test_json.py @@ -9,7 +9,7 @@ from django.core.serializers.json import DjangoJSONEncoder from django.db import models from django.test import SimpleTestCase, TestCase, TransactionTestCase from django.test.utils import isolate_apps -from django.utils.translation import override, ugettext_lazy +from django.utils.translation import gettext_lazy, override from .models import Score from .tests import SerializersTestBase, SerializersTransactionTestBase @@ -292,12 +292,12 @@ class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact class DjangoJSONEncoderTests(SimpleTestCase): def test_lazy_string_encoding(self): self.assertEqual( - json.dumps({'lang': ugettext_lazy("French")}, cls=DjangoJSONEncoder), + json.dumps({'lang': gettext_lazy("French")}, cls=DjangoJSONEncoder), '{"lang": "French"}' ) with override('fr'): self.assertEqual( - json.dumps({'lang': ugettext_lazy("French")}, cls=DjangoJSONEncoder), + json.dumps({'lang': gettext_lazy("French")}, cls=DjangoJSONEncoder), '{"lang": "Fran\\u00e7ais"}' ) diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index e4fd2bb8fe..1231568c37 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -17,7 +17,7 @@ from django.test import ( from django.test.client import RedirectCycleError, RequestFactory, encode_file from django.test.utils import ContextList from django.urls import NoReverseMatch, reverse -from django.utils.translation import ugettext_lazy +from django.utils.translation import gettext_lazy from .models import CustomUser from .views import CustomTestException @@ -154,11 +154,11 @@ class AssertContainsTests(SimpleTestCase): def test_nontext_contains(self): r = self.client.get('/no_template_view/') - self.assertContains(r, ugettext_lazy('once')) + self.assertContains(r, gettext_lazy('once')) def test_nontext_not_contains(self): r = self.client.get('/no_template_view/') - self.assertNotContains(r, ugettext_lazy('never')) + self.assertNotContains(r, gettext_lazy('never')) def test_assert_contains_renders_template_response(self): """ diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py index 22695277a4..a869ced774 100644 --- a/tests/utils_tests/test_text.py +++ b/tests/utils_tests/test_text.py @@ -4,7 +4,7 @@ from django.test import SimpleTestCase from django.utils import text from django.utils.functional import lazystr from django.utils.text import format_lazy -from django.utils.translation import override, ugettext_lazy +from django.utils.translation import gettext_lazy, override IS_WIDE_BUILD = (len('\U0001F4A9') == 1) @@ -235,7 +235,7 @@ class TestUtilsText(SimpleTestCase): # The format string can be lazy. (string comes from contrib.admin) s = format_lazy( - ugettext_lazy("Added {name} \"{object}\"."), + gettext_lazy("Added {name} \"{object}\"."), name='article', object='My first try', ) with override('fr'): diff --git a/tests/view_tests/urls.py b/tests/view_tests/urls.py index a942662845..bb450717a8 100644 --- a/tests/view_tests/urls.py +++ b/tests/view_tests/urls.py @@ -3,7 +3,7 @@ from os import path from django.conf.urls import include, url from django.conf.urls.i18n import i18n_patterns -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views import defaults, i18n, static from . import views