mirror of https://github.com/django/django.git
Fixed #2920 -- Removed _() from builtins.
This is backwards incompatible, but easy to work around. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6582 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5f51964be2
commit
7ca708140a
|
@ -140,13 +140,3 @@ class UserSettingsHolder(object):
|
|||
|
||||
settings = LazySettings()
|
||||
|
||||
# This function replaces itself with django.utils.translation.gettext() the
|
||||
# first time it's run. This is necessary because the import of
|
||||
# django.utils.translation requires a working settings module, and loading it
|
||||
# from within this file would cause a circular import.
|
||||
def first_time_gettext(*args):
|
||||
from django.utils.translation import gettext
|
||||
__builtins__['_'] = gettext
|
||||
return gettext(*args)
|
||||
|
||||
__builtins__['_'] = first_time_gettext
|
||||
|
|
|
@ -8,7 +8,7 @@ __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',
|
|||
'ngettext_lazy', 'string_concat', 'activate', 'deactivate',
|
||||
'get_language', 'get_language_bidi', 'get_date_formats',
|
||||
'get_partial_date_formats', 'check_for_language', 'to_locale',
|
||||
'get_language_from_request', 'install', 'templatize', 'ugettext',
|
||||
'get_language_from_request', 'templatize', 'ugettext',
|
||||
'ungettext', 'deactivate_all']
|
||||
|
||||
# Here be dragons, so a short explanation of the logic won't hurt:
|
||||
|
@ -96,9 +96,6 @@ def to_locale(language):
|
|||
def get_language_from_request(request):
|
||||
return real_get_language_from_request(request)
|
||||
|
||||
def install():
|
||||
return real_install()
|
||||
|
||||
def templatize(src):
|
||||
return real_templatize(src)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ def ungettext(singular, plural, number):
|
|||
return force_unicode(ngettext(singular, plural, number))
|
||||
|
||||
activate = lambda x: None
|
||||
deactivate = deactivate_all = install = lambda: None
|
||||
deactivate = deactivate_all = lambda: None
|
||||
get_language = lambda: settings.LANGUAGE_CODE
|
||||
get_language_bidi = lambda: settings.LANGUAGE_CODE in settings.LANGUAGES_BIDI
|
||||
get_date_formats = lambda: (settings.DATE_FORMAT, settings.DATETIME_FORMAT, settings.TIME_FORMAT)
|
||||
|
|
|
@ -249,8 +249,10 @@ def catalog():
|
|||
|
||||
def do_translate(message, translation_function):
|
||||
"""
|
||||
Translate 'message' using the given 'translation_function' name -- which
|
||||
will be either gettext or ugettext.
|
||||
Translates 'message' using the given 'translation_function' name -- which
|
||||
will be either gettext or ugettext. It uses the current thread to find the
|
||||
translation object to use. If no current translation is activated, the
|
||||
message will be run through the default translation object.
|
||||
"""
|
||||
global _default, _active
|
||||
t = _active.get(currentThread(), None)
|
||||
|
@ -262,12 +264,6 @@ def do_translate(message, translation_function):
|
|||
return getattr(_default, translation_function)(message)
|
||||
|
||||
def gettext(message):
|
||||
"""
|
||||
This function will be patched into the builtins module to provide the _
|
||||
helper function. It will use the current thread as a discriminator to find
|
||||
the translation object to use. If no current translation is activated, the
|
||||
message will be run through the default translation object.
|
||||
"""
|
||||
return do_translate(message, 'gettext')
|
||||
|
||||
def ugettext(message):
|
||||
|
@ -414,13 +410,6 @@ def get_partial_date_formats():
|
|||
month_day_format = settings.MONTH_DAY_FORMAT
|
||||
return year_month_format, month_day_format
|
||||
|
||||
def install():
|
||||
"""
|
||||
Installs the gettext function as the default translation function under
|
||||
the name '_'.
|
||||
"""
|
||||
__builtins__['_'] = gettext
|
||||
|
||||
dot_re = re.compile(r'\S')
|
||||
def blankout(src, char):
|
||||
"""
|
||||
|
|
|
@ -13,7 +13,7 @@ from datetime import datetime, timedelta
|
|||
from django import template
|
||||
from django.template import loader
|
||||
from django.template.loaders import app_directories, filesystem
|
||||
from django.utils.translation import activate, deactivate, install, ugettext as _
|
||||
from django.utils.translation import activate, deactivate, ugettext as _
|
||||
from django.utils.tzinfo import LocalTimezone
|
||||
|
||||
from unicode import unicode_tests
|
||||
|
@ -844,8 +844,6 @@ class Templates(unittest.TestCase):
|
|||
expected_invalid_str = 'INVALID'
|
||||
|
||||
for name, vals in tests:
|
||||
install()
|
||||
|
||||
if isinstance(vals[2], tuple):
|
||||
normal_string_result = vals[2][0]
|
||||
invalid_string_result = vals[2][1]
|
||||
|
|
Loading…
Reference in New Issue