Skip to content

Commit 3916cfb

Browse files
committed
unicode: Replaced all implicit uses of _() from builtins with explicitly
importing ugettext and aliasing it to _. Refs #2920. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5230 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent a4adfd7 commit 3916cfb

File tree

17 files changed

+62
-54
lines changed

17 files changed

+62
-54
lines changed

django/contrib/admin/filterspecs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from django.db import models
1010
from django.utils.encoding import smart_unicode
11+
from django.utils.translation import ugettext as _
1112
import datetime
1213

1314
class FilterSpec(object):

django/contrib/admin/templatetags/admin_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.utils import dateformat
77
from django.utils.html import escape
88
from django.utils.text import capfirst
9-
from django.utils.translation import get_date_formats, get_partial_date_formats
9+
from django.utils.translation import get_date_formats, get_partial_date_formats, ugettext as _
1010
from django.utils.encoding import smart_unicode, smart_str
1111
from django.template import Library
1212
import datetime

django/contrib/admin/views/auth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.shortcuts import render_to_response, get_object_or_404
77
from django.http import HttpResponseRedirect
88
from django.utils.html import escape
9+
from django.utils.translation import ugettext as _
910

1011
def user_add_stage(request):
1112
if not request.user.has_perm('auth.change_user'):

django/contrib/admin/views/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.contrib.auth.models import User
44
from django.contrib.auth import authenticate, login
55
from django.shortcuts import render_to_response
6-
from django.utils.translation import ugettext_lazy
6+
from django.utils.translation import ugettext_lazy, ugettext as _
77
import base64, datetime, md5
88
import cPickle as pickle
99

django/contrib/admin/views/doc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.core import urlresolvers
1010
from django.contrib.admin import utils
1111
from django.contrib.sites.models import Site
12+
from django.utils.translation import ugettext as _
1213
import inspect, os, re
1314

1415
# Exclude methods starting with these strings from documentation

django/contrib/admin/views/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from django.utils.html import escape
1414
from django.utils.text import capfirst, get_text_list
1515
from django.utils.encoding import smart_unicode
16+
from django.utils.translation import ugettext as _
1617
import operator
1718

1819
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION

django/contrib/auth/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.core.exceptions import ImproperlyConfigured
33
from django.db import backend, connection, models
44
from django.contrib.contenttypes.models import ContentType
5-
from django.utils.translation import ugettext_lazy
5+
from django.utils.translation import ugettext_lazy, ugettext as _
66
import datetime
77

88
def check_password(raw_password, enc_password):

django/contrib/auth/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.http import HttpResponseRedirect
88
from django.contrib.auth.decorators import login_required
99
from django.contrib.auth import REDIRECT_FIELD_NAME
10+
from django.utils.translation import ugettext as _
1011

1112
def login(request, template_name='registration/login.html'):
1213
"Displays the login form and handles the login action."

django/contrib/comments/views/karma.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.shortcuts import render_to_response
33
from django.template import RequestContext
44
from django.contrib.comments.models import Comment, KarmaScore
5+
from django.utils.translation import ugettext as _
56

67
def vote(request, comment_id, vote):
78
"""

django/core/validators.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import urllib2
1212
from django.conf import settings
13-
from django.utils.translation import ugettext, ugettext_lazy, ungettext
13+
from django.utils.translation import ugettext as _, ugettext_lazy, ungettext
1414
from django.utils.functional import Promise, lazy
1515
import re
1616

@@ -61,30 +61,30 @@ def __str__(self):
6161

6262
def isAlphaNumeric(field_data, all_data):
6363
if not alnum_re.search(field_data):
64-
raise ValidationError, ugettext("This value must contain only letters, numbers and underscores.")
64+
raise ValidationError, _("This value must contain only letters, numbers and underscores.")
6565

6666
def isAlphaNumericURL(field_data, all_data):
6767
if not alnumurl_re.search(field_data):
68-
raise ValidationError, ugettext("This value must contain only letters, numbers, underscores, dashes or slashes.")
68+
raise ValidationError, _("This value must contain only letters, numbers, underscores, dashes or slashes.")
6969

7070
def isSlug(field_data, all_data):
7171
if not slug_re.search(field_data):
72-
raise ValidationError, ugettext("This value must contain only letters, numbers, underscores or hyphens.")
72+
raise ValidationError, _("This value must contain only letters, numbers, underscores or hyphens.")
7373

7474
def isLowerCase(field_data, all_data):
7575
if field_data.lower() != field_data:
76-
raise ValidationError, ugettext("Uppercase letters are not allowed here.")
76+
raise ValidationError, _("Uppercase letters are not allowed here.")
7777

7878
def isUpperCase(field_data, all_data):
7979
if field_data.upper() != field_data:
80-
raise ValidationError, ugettext("Lowercase letters are not allowed here.")
80+
raise ValidationError, _("Lowercase letters are not allowed here.")
8181

8282
def isCommaSeparatedIntegerList(field_data, all_data):
8383
for supposed_int in field_data.split(','):
8484
try:
8585
int(supposed_int)
8686
except ValueError:
87-
raise ValidationError, ugettext("Enter only digits separated by commas.")
87+
raise ValidationError, _("Enter only digits separated by commas.")
8888

8989
def isCommaSeparatedEmailList(field_data, all_data):
9090
"""
@@ -96,32 +96,32 @@ def isCommaSeparatedEmailList(field_data, all_data):
9696
try:
9797
isValidEmail(supposed_email.strip(), '')
9898
except ValidationError:
99-
raise ValidationError, ugettext("Enter valid e-mail addresses separated by commas.")
99+
raise ValidationError, _("Enter valid e-mail addresses separated by commas.")
100100

101101
def isValidIPAddress4(field_data, all_data):
102102
if not ip4_re.search(field_data):
103-
raise ValidationError, ugettext("Please enter a valid IP address.")
103+
raise ValidationError, _("Please enter a valid IP address.")
104104

105105
def isNotEmpty(field_data, all_data):
106106
if field_data.strip() == '':
107-
raise ValidationError, ugettext("Empty values are not allowed here.")
107+
raise ValidationError, _("Empty values are not allowed here.")
108108

109109
def isOnlyDigits(field_data, all_data):
110110
if not field_data.isdigit():
111-
raise ValidationError, ugettext("Non-numeric characters aren't allowed here.")
111+
raise ValidationError, _("Non-numeric characters aren't allowed here.")
112112

113113
def isNotOnlyDigits(field_data, all_data):
114114
if field_data.isdigit():
115-
raise ValidationError, ugettext("This value can't be comprised solely of digits.")
115+
raise ValidationError, _("This value can't be comprised solely of digits.")
116116

117117
def isInteger(field_data, all_data):
118118
# This differs from isOnlyDigits because this accepts the negative sign
119119
if not integer_re.search(field_data):
120-
raise ValidationError, ugettext("Enter a whole number.")
120+
raise ValidationError, _("Enter a whole number.")
121121

122122
def isOnlyLetters(field_data, all_data):
123123
if not field_data.isalpha():
124-
raise ValidationError, ugettext("Only alphabetical characters are allowed here.")
124+
raise ValidationError, _("Only alphabetical characters are allowed here.")
125125

126126
def _isValidDate(date_string):
127127
"""
@@ -136,30 +136,30 @@ def _isValidDate(date_string):
136136
# This check is needed because strftime is used when saving the date
137137
# value to the database, and strftime requires that the year be >=1900.
138138
if year < 1900:
139-
raise ValidationError, ugettext('Year must be 1900 or later.')
139+
raise ValidationError, _('Year must be 1900 or later.')
140140
try:
141141
date(year, month, day)
142142
except ValueError, e:
143-
msg = ugettext('Invalid date: %s') % ugettext(str(e))
143+
msg = _('Invalid date: %s') % _(str(e))
144144
raise ValidationError, msg
145145

146146
def isValidANSIDate(field_data, all_data):
147147
if not ansi_date_re.search(field_data):
148-
raise ValidationError, ugettext('Enter a valid date in YYYY-MM-DD format.')
148+
raise ValidationError, _('Enter a valid date in YYYY-MM-DD format.')
149149
_isValidDate(field_data)
150150

151151
def isValidANSITime(field_data, all_data):
152152
if not ansi_time_re.search(field_data):
153-
raise ValidationError, ugettext('Enter a valid time in HH:MM format.')
153+
raise ValidationError, _('Enter a valid time in HH:MM format.')
154154

155155
def isValidANSIDatetime(field_data, all_data):
156156
if not ansi_datetime_re.search(field_data):
157-
raise ValidationError, ugettext('Enter a valid date/time in YYYY-MM-DD HH:MM format.')
157+
raise ValidationError, _('Enter a valid date/time in YYYY-MM-DD HH:MM format.')
158158
_isValidDate(field_data.split()[0])
159159

160160
def isValidEmail(field_data, all_data):
161161
if not email_re.search(field_data):
162-
raise ValidationError, ugettext('Enter a valid e-mail address.')
162+
raise ValidationError, _('Enter a valid e-mail address.')
163163

164164
def isValidImage(field_data, all_data):
165165
"""
@@ -171,34 +171,34 @@ def isValidImage(field_data, all_data):
171171
try:
172172
content = field_data['content']
173173
except TypeError:
174-
raise ValidationError, ugettext("No file was submitted. Check the encoding type on the form.")
174+
raise ValidationError, _("No file was submitted. Check the encoding type on the form.")
175175
try:
176176
Image.open(StringIO(content))
177177
except IOError: # Python Imaging Library doesn't recognize it as an image
178-
raise ValidationError, ugettext("Upload a valid image. The file you uploaded was either not an image or a corrupted image.")
178+
raise ValidationError, _("Upload a valid image. The file you uploaded was either not an image or a corrupted image.")
179179

180180
def isValidImageURL(field_data, all_data):
181181
uc = URLMimeTypeCheck(('image/jpeg', 'image/gif', 'image/png'))
182182
try:
183183
uc(field_data, all_data)
184184
except URLMimeTypeCheck.InvalidContentType:
185-
raise ValidationError, ugettext("The URL %s does not point to a valid image.") % field_data
185+
raise ValidationError, _("The URL %s does not point to a valid image.") % field_data
186186

187187
def isValidPhone(field_data, all_data):
188188
if not phone_re.search(field_data):
189-
raise ValidationError, ugettext('Phone numbers must be in XXX-XXX-XXXX format. "%s" is invalid.') % field_data
189+
raise ValidationError, _('Phone numbers must be in XXX-XXX-XXXX format. "%s" is invalid.') % field_data
190190

191191
def isValidQuicktimeVideoURL(field_data, all_data):
192192
"Checks that the given URL is a video that can be played by QuickTime (qt, mpeg)"
193193
uc = URLMimeTypeCheck(('video/quicktime', 'video/mpeg',))
194194
try:
195195
uc(field_data, all_data)
196196
except URLMimeTypeCheck.InvalidContentType:
197-
raise ValidationError, ugettext("The URL %s does not point to a valid QuickTime video.") % field_data
197+
raise ValidationError, _("The URL %s does not point to a valid QuickTime video.") % field_data
198198

199199
def isValidURL(field_data, all_data):
200200
if not url_re.search(field_data):
201-
raise ValidationError, ugettext("A valid URL is required.")
201+
raise ValidationError, _("A valid URL is required.")
202202

203203
def isValidHTML(field_data, all_data):
204204
import urllib, urllib2
@@ -212,14 +212,14 @@ def isValidHTML(field_data, all_data):
212212
return
213213
from xml.dom.minidom import parseString
214214
error_messages = [e.firstChild.wholeText for e in parseString(u.read()).getElementsByTagName('messages')[0].getElementsByTagName('msg')]
215-
raise ValidationError, ugettext("Valid HTML is required. Specific errors are:\n%s") % "\n".join(error_messages)
215+
raise ValidationError, _("Valid HTML is required. Specific errors are:\n%s") % "\n".join(error_messages)
216216

217217
def isWellFormedXml(field_data, all_data):
218218
from xml.dom.minidom import parseString
219219
try:
220220
parseString(field_data)
221221
except Exception, e: # Naked except because we're not sure what will be thrown
222-
raise ValidationError, ugettext("Badly formed XML: %s") % str(e)
222+
raise ValidationError, _("Badly formed XML: %s") % str(e)
223223

224224
def isWellFormedXmlFragment(field_data, all_data):
225225
isWellFormedXml('<root>%s</root>' % field_data, all_data)
@@ -249,7 +249,7 @@ def isValidUSState(field_data, all_data):
249249
"Checks that the given string is a valid two-letter U.S. state abbreviation"
250250
states = ['AA', 'AE', 'AK', 'AL', 'AP', 'AR', 'AS', 'AZ', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'FM', 'GA', 'GU', 'HI', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA', 'MD', 'ME', 'MH', 'MI', 'MN', 'MO', 'MP', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'PR', 'PW', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VA', 'VI', 'VT', 'WA', 'WI', 'WV', 'WY']
251251
if field_data.upper() not in states:
252-
raise ValidationError, ugettext("Enter a valid U.S. state abbreviation.")
252+
raise ValidationError, _("Enter a valid U.S. state abbreviation.")
253253

254254
def hasNoProfanities(field_data, all_data):
255255
"""
@@ -364,11 +364,11 @@ def __init__(self, lower=None, upper=None, error_message=''):
364364
self.lower, self.upper = lower, upper
365365
if not error_message:
366366
if lower and upper:
367-
self.error_message = ugettext("This value must be between %(lower)s and %(upper)s.") % {'lower': lower, 'upper': upper}
367+
self.error_message = _("This value must be between %(lower)s and %(upper)s.") % {'lower': lower, 'upper': upper}
368368
elif lower:
369-
self.error_message = ugettext("This value must be at least %s.") % lower
369+
self.error_message = _("This value must be at least %s.") % lower
370370
elif upper:
371-
self.error_message = ugettext("This value must be no more than %s.") % upper
371+
self.error_message = _("This value must be no more than %s.") % upper
372372
else:
373373
self.error_message = error_message
374374

@@ -404,7 +404,7 @@ def __call__(self, field_data, all_data):
404404
from math import log
405405
val = log(int(field_data)) / log(self.power_of)
406406
if val != int(val):
407-
raise ValidationError, ugettext("This value must be a power of %s.") % self.power_of
407+
raise ValidationError, _("This value must be a power of %s.") % self.power_of
408408

409409
class IsValidFloat(object):
410410
def __init__(self, max_digits, decimal_places):
@@ -415,7 +415,7 @@ def __call__(self, field_data, all_data):
415415
try:
416416
float(data)
417417
except ValueError:
418-
raise ValidationError, ugettext("Please enter a valid decimal number.")
418+
raise ValidationError, _("Please enter a valid decimal number.")
419419
# Negative floats require more space to input.
420420
max_allowed_length = data.startswith('-') and (self.max_digits + 2) or (self.max_digits + 1)
421421
if len(data) > max_allowed_length:
@@ -504,10 +504,10 @@ def __call__(self, field_data, all_data):
504504
try:
505505
info = urllib2.urlopen(field_data).info()
506506
except (urllib2.HTTPError, urllib2.URLError):
507-
raise URLMimeTypeCheck.CouldNotRetrieve, ugettext("Could not retrieve anything from %s.") % field_data
507+
raise URLMimeTypeCheck.CouldNotRetrieve, _("Could not retrieve anything from %s.") % field_data
508508
content_type = info['content-type']
509509
if content_type not in self.mime_type_list:
510-
raise URLMimeTypeCheck.InvalidContentType, ugettext("The URL %(url)s returned the invalid Content-Type header '%(contenttype)s'.") % {
510+
raise URLMimeTypeCheck.InvalidContentType, _("The URL %(url)s returned the invalid Content-Type header '%(contenttype)s'.") % {
511511
'url': field_data, 'contenttype': content_type}
512512

513513
class RelaxNGCompact(object):

0 commit comments

Comments
 (0)