Ticket #4796: 4796-hopeful-fix.diff

File 4796-hopeful-fix.diff, 2.2 KB (added by Malcolm Tredinnick, 17 years ago)

If somebody can reproduce the problem, does this patch fix it?

  • django/utils/translation/__init__.py

    diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
    index 13fc8a8..a831c83 100644
    a b  
    22Internationalization support.
    33"""
    44from django.utils.functional import lazy
     5import traceback
     6import threading
    57
    68__all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',
    79        'ngettext_lazy', 'string_concat', 'activate', 'deactivate',
    __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',  
    1820# replace the functions with their real counterparts (once we do access the
    1921# settings).
    2022
     23_init_lock = threading.Lock()
     24_initialised = False
     25
    2126def delayed_loader(*args, **kwargs):
    2227    """
    2328    Replace each real_* function with the corresponding function from either
    def delayed_loader(*args, **kwargs):  
    2631    first time any i18n method is called. It replaces all the i18n methods at
    2732    once at that time.
    2833    """
    29     import traceback
    30     from django.conf import settings
    31     if settings.USE_I18N:
    32         import trans_real as trans
    33     else:
    34         import trans_null as trans
    35     caller = traceback.extract_stack(limit=2)[0][2]
    36     g = globals()
    37     for name in __all__:
    38         if hasattr(trans, name):
    39             g['real_%s' % name] = getattr(trans, name)
    40 
    41     # Make the originally requested function call on the way out the door.
    42     return g[caller](*args, **kwargs)
     34    global _initialised
     35    _init_lock.acquire()
     36    try:
     37        caller = traceback.extract_stack(limit=2)[0][2]
     38        g = globals()
     39        if not _initialised:
     40            from django.conf import settings
     41            if settings.USE_I18N:
     42                import trans_real as trans
     43            else:
     44                import trans_null as trans
     45            for name in __all__:
     46                if hasattr(trans, name):
     47                    g['real_%s' % name] = getattr(trans, name)
     48            _initialised = True
     49
     50        # Make the originally requested function call on the way out the door.
     51        return g[caller](*args, **kwargs)
     52    finally:
     53        _init_lock.release()
    4354
    4455g = globals()
    4556for name in __all__:
Back to Top