Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refs #2920 -- Replaced implicit uses of _() with explicit imports or …

…calls to gettext(). At some point post 0.96, we need to remove the calls that put _ into the builtins.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4485 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0e924c70b1ec5cae635a99d9fe7e279698dc5cd0 1 parent b767b58
Russell Keith-Magee authored February 11, 2007
1  django/contrib/admin/filterspecs.py
@@ -7,6 +7,7 @@
7 7
 """
8 8
 
9 9
 from django.db import models
  10
+from django.utils.translation import gettext as _
10 11
 import datetime
11 12
 
12 13
 class FilterSpec(object):
2  django/contrib/admin/templatetags/admin_list.py
@@ -6,7 +6,7 @@
6 6
 from django.utils import dateformat
7 7
 from django.utils.html import escape
8 8
 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, gettext as _
10 10
 from django.template import Library
11 11
 import datetime
12 12
 
1  django/contrib/admin/views/auth.py
@@ -6,6 +6,7 @@
6 6
 from django.shortcuts import render_to_response, get_object_or_404
7 7
 from django.http import HttpResponseRedirect
8 8
 from django.utils.html import escape
  9
+from django.utils.translation import gettext as _
9 10
 
10 11
 def user_add_stage(request):
11 12
     if not request.user.has_perm('auth.change_user'):
2  django/contrib/admin/views/decorators.py
@@ -3,7 +3,7 @@
3 3
 from django.contrib.auth.models import User
4 4
 from django.contrib.auth import authenticate, login
5 5
 from django.shortcuts import render_to_response
6  
-from django.utils.translation import gettext_lazy
  6
+from django.utils.translation import gettext_lazy, gettext as _
7 7
 import base64, datetime, md5
8 8
 import cPickle as pickle
9 9
 
1  django/contrib/admin/views/doc.py
@@ -9,6 +9,7 @@
9 9
 from django.core import urlresolvers
10 10
 from django.contrib.admin import utils
11 11
 from django.contrib.sites.models import Site
  12
+from django.utils.translation import gettext as _
12 13
 import inspect, os, re
13 14
 
14 15
 # Exclude methods starting with these strings from documentation
1  django/contrib/admin/views/main.py
@@ -12,6 +12,7 @@
12 12
 from django.http import Http404, HttpResponse, HttpResponseRedirect
13 13
 from django.utils.html import escape
14 14
 from django.utils.text import capfirst, get_text_list
  15
+from django.utils.translation import gettext as _
15 16
 import operator
16 17
 
17 18
 from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION
1  django/contrib/auth/views.py
@@ -7,6 +7,7 @@
7 7
 from django.http import HttpResponseRedirect
8 8
 from django.contrib.auth.decorators import login_required
9 9
 from django.contrib.auth import LOGIN_URL, REDIRECT_FIELD_NAME
  10
+from django.utils.translation import gettext as _
10 11
 
11 12
 def login(request, template_name='registration/login.html'):
12 13
     "Displays the login form and handles the login action."
2  django/contrib/comments/views/comments.py
@@ -11,7 +11,7 @@
11 11
 from django.http import HttpResponseRedirect
12 12
 from django.utils.text import normalize_newlines
13 13
 from django.conf import settings
14  
-from django.utils.translation import ngettext
  14
+from django.utils.translation import ngettext, gettext as _
15 15
 import base64, datetime
16 16
 
17 17
 COMMENTS_PER_PAGE = 20
1  django/contrib/comments/views/karma.py
@@ -2,6 +2,7 @@
2 2
 from django.shortcuts import render_to_response
3 3
 from django.template import RequestContext
4 4
 from django.contrib.comments.models import Comment, KarmaScore
  5
+from django.utils.translation import gettext as _
5 6
 
6 7
 def vote(request, comment_id, vote):
7 8
     """
1  django/core/cache/__init__.py
@@ -18,6 +18,7 @@
18 18
 from cgi import parse_qsl
19 19
 from django.conf import settings
20 20
 from django.core.cache.backends.base import InvalidCacheBackendError
  21
+from django.utils.translation import gettext as _
21 22
 
22 23
 BACKENDS = {
23 24
     # name for use in settings file --> name of module in "backends" directory
18  django/core/validators.py
@@ -235,14 +235,14 @@ def isExistingURL(field_data, all_data):
235 235
         req = urllib2.Request(field_data,None, headers)
236 236
         u = urllib2.urlopen(req)
237 237
     except ValueError:
238  
-        raise ValidationError, _("Invalid URL: %s") % field_data
  238
+        raise ValidationError, gettext("Invalid URL: %s") % field_data
239 239
     except urllib2.HTTPError, e:
240 240
         # 401s are valid; they just mean authorization is required.
241 241
         # 301 and 302 are redirects; they just mean look somewhere else.
242 242
         if str(e.code) not in ('401','301','302'):
243  
-            raise ValidationError, _("The URL %s is a broken link.") % field_data
  243
+            raise ValidationError, gettext("The URL %s is a broken link.") % field_data
244 244
     except: # urllib2.URLError, httplib.InvalidURL, etc.
245  
-        raise ValidationError, _("The URL %s is a broken link.") % field_data
  245
+        raise ValidationError, gettext("The URL %s is a broken link.") % field_data
246 246
         
247 247
 def isValidUSState(field_data, all_data):
248 248
     "Checks that the given string is a valid two-letter U.S. state abbreviation"
@@ -537,30 +537,30 @@ def __call__(self, field_data, all_data):
537 537
             # Scrape the Jing error messages to reword them more nicely.
538 538
             m = re.search(r'Expected "(.*?)" to terminate element starting on line (\d+)', message)
539 539
             if m:
540  
-                display_errors.append(_('Please close the unclosed %(tag)s tag from line %(line)s. (Line starts with "%(start)s".)') % \
  540
+                display_errors.append(gettext('Please close the unclosed %(tag)s tag from line %(line)s. (Line starts with "%(start)s".)') % \
541 541
                     {'tag':m.group(1).replace('/', ''), 'line':m.group(2), 'start':lines[int(m.group(2)) - 1][:30]})
542 542
                 continue
543 543
             if message.strip() == 'text not allowed here':
544  
-                display_errors.append(_('Some text starting on line %(line)s is not allowed in that context. (Line starts with "%(start)s".)') % \
  544
+                display_errors.append(gettext('Some text starting on line %(line)s is not allowed in that context. (Line starts with "%(start)s".)') % \
545 545
                     {'line':line, 'start':lines[int(line) - 1][:30]})
546 546
                 continue
547 547
             m = re.search(r'\s*attribute "(.*?)" not allowed at this point; ignored', message)
548 548
             if m:
549  
-                display_errors.append(_('"%(attr)s" on line %(line)s is an invalid attribute. (Line starts with "%(start)s".)') % \
  549
+                display_errors.append(gettext('"%(attr)s" on line %(line)s is an invalid attribute. (Line starts with "%(start)s".)') % \
550 550
                     {'attr':m.group(1), 'line':line, 'start':lines[int(line) - 1][:30]})
551 551
                 continue
552 552
             m = re.search(r'\s*unknown element "(.*?)"', message)
553 553
             if m:
554  
-                display_errors.append(_('"<%(tag)s>" on line %(line)s is an invalid tag. (Line starts with "%(start)s".)') % \
  554
+                display_errors.append(gettext('"<%(tag)s>" on line %(line)s is an invalid tag. (Line starts with "%(start)s".)') % \
555 555
                     {'tag':m.group(1), 'line':line, 'start':lines[int(line) - 1][:30]})
556 556
                 continue
557 557
             if message.strip() == 'required attributes missing':
558  
-                display_errors.append(_('A tag on line %(line)s is missing one or more required attributes. (Line starts with "%(start)s".)') % \
  558
+                display_errors.append(gettext('A tag on line %(line)s is missing one or more required attributes. (Line starts with "%(start)s".)') % \
559 559
                     {'line':line, 'start':lines[int(line) - 1][:30]})
560 560
                 continue
561 561
             m = re.search(r'\s*bad value for attribute "(.*?)"', message)
562 562
             if m:
563  
-                display_errors.append(_('The "%(attr)s" attribute on line %(line)s has an invalid value. (Line starts with "%(start)s".)') % \
  563
+                display_errors.append(gettext('The "%(attr)s" attribute on line %(line)s has an invalid value. (Line starts with "%(start)s".)') % \
564 564
                     {'attr':m.group(1), 'line':line, 'start':lines[int(line) - 1][:30]})
565 565
                 continue
566 566
             # Failing all those checks, use the default error message.
1  django/db/__init__.py
... ...
@@ -1,6 +1,7 @@
1 1
 from django.conf import settings
2 2
 from django.core import signals
3 3
 from django.dispatch import dispatcher
  4
+from django.utils.translation import gettext as _
4 5
 
5 6
 __all__ = ('backend', 'connection', 'DatabaseError')
6 7
 
2  django/db/models/fields/__init__.py
@@ -616,7 +616,7 @@ def __call__(self, field_data, all_data):
616 616
         def isWithinMediaRoot(field_data, all_data):
617 617
             f = os.path.abspath(os.path.join(settings.MEDIA_ROOT, field_data))
618 618
             if not f.startswith(os.path.abspath(os.path.normpath(settings.MEDIA_ROOT))):
619  
-                raise validators.ValidationError, _("Enter a valid filename.")
  619
+                raise validators.ValidationError, gettext("Enter a valid filename.")
620 620
         field_list[1].validator_list.append(isWithinMediaRoot)
621 621
         return field_list
622 622
 
4  django/db/models/fields/related.py
@@ -3,7 +3,7 @@
@@ -50,7 +50,7 @@ def manipulator_valid_rel_key(f, self, field_data, all_data):
1  django/db/models/manipulators.py
@@ -7,6 +7,7 @@
7 7
 from django.utils.functional import curry
8 8
 from django.utils.datastructures import DotExpandedDict
9 9
 from django.utils.text import capfirst
  10
+from django.utils.translation import gettext as _
10 11
 import types
11 12
 
12 13
 def add_manipulators(sender):
1  django/http/__init__.py
@@ -3,6 +3,7 @@
3 3
 from pprint import pformat
4 4
 from urllib import urlencode, quote
5 5
 from django.utils.datastructures import MultiValueDict
  6
+from django.utils.translation import gettext as _
6 7
 
7 8
 RESERVED_CHARS="!*'();:@&=+$,/?%#[]"
8 9
 
2  django/oldforms/__init__.py
@@ -569,7 +569,7 @@ class NullBooleanField(SelectField):
569 569
     "This SelectField provides 'Yes', 'No' and 'Unknown', mapping results to True, False or None"
570 570
     def __init__(self, field_name, is_required=False, validator_list=None):
571 571
         if validator_list is None: validator_list = []
572  
-        SelectField.__init__(self, field_name, choices=[('1', _('Unknown')), ('2', _('Yes')), ('3', _('No'))],
  572
+        SelectField.__init__(self, field_name, choices=[('1', gettext('Unknown')), ('2', gettext('Yes')), ('3', gettext('No'))],
573 573
             is_required=is_required, validator_list=validator_list)
574 574
 
575 575
     def render(self, data):
1  django/test/simple.py
@@ -3,6 +3,7 @@
3 3
 from django.core import management
4 4
 from django.test.utils import setup_test_environment, teardown_test_environment
5 5
 from django.test.utils import create_test_db, destroy_test_db
  6
+from django.utils.translation import gettext as _
6 7
 from django.test.testcases import OutputChecker, DocTestRunner
7 8
 
8 9
 # The module name for tests outside models.py
10  django/utils/translation/trans_real.py
@@ -359,9 +359,9 @@ def get_date_formats():
359 359
     one, the formats provided in the settings will be used.
360 360
     """
361 361
     from django.conf import settings
362  
-    date_format = _('DATE_FORMAT')
363  
-    datetime_format = _('DATETIME_FORMAT')
364  
-    time_format = _('TIME_FORMAT')
  362
+    date_format = gettext('DATE_FORMAT')
  363
+    datetime_format = gettext('DATETIME_FORMAT')
  364
+    time_format = gettext('TIME_FORMAT')
365 365
     if date_format == 'DATE_FORMAT':
366 366
         date_format = settings.DATE_FORMAT
367 367
     if datetime_format == 'DATETIME_FORMAT':
@@ -377,8 +377,8 @@ def get_partial_date_formats():
377 377
     one, the formats provided in the settings will be used.
378 378
     """
379 379
     from django.conf import settings
380  
-    year_month_format = _('YEAR_MONTH_FORMAT')
381  
-    month_day_format = _('MONTH_DAY_FORMAT')
  380
+    year_month_format = gettext('YEAR_MONTH_FORMAT')
  381
+    month_day_format = gettext('MONTH_DAY_FORMAT')
382 382
     if year_month_format == 'YEAR_MONTH_FORMAT':
383 383
         year_month_format = settings.YEAR_MONTH_FORMAT
384 384
     if month_day_format == 'MONTH_DAY_FORMAT':
1  tests/regressiontests/defaultfilters/tests.py
@@ -391,6 +391,7 @@
391 391
 """
392 392
 
393 393
 from django.template.defaultfilters import *
  394
+from django.utils.translation import gettext as _
394 395
 import datetime
395 396
 
396 397
 if __name__ == '__main__':

0 notes on commit 0e924c7

Please sign in to comment.
Something went wrong with that request. Please try again.