Ticket #14894: trans_multithreading_fix.diff
File trans_multithreading_fix.diff, 1.4 KB (added by , 14 years ago) |
---|
-
django/utils/translation/trans_real.py
4 4 import os 5 5 import re 6 6 import sys 7 import threading 7 8 import warnings 8 9 import gettext as gettext_module 9 10 from cStringIO import StringIO … … 17 18 _translations = {} 18 19 _active = {} 19 20 21 _translations_lock = threading.Lock() 22 20 23 # The default translation is based on the settings file. 21 24 _default = None 22 25 … … 144 147 # the same translation object (thus, merging en-us with a local update 145 148 # doesn't affect en-gb), even though they will both use the core "en" 146 149 # translation. So we have to subvert Python's internal gettext caching. 150 _translations_lock.acquire() 147 151 base_lang = lambda x: x.split('-', 1)[0] 148 152 if base_lang(lang) in [base_lang(trans) for trans in _translations]: 149 153 res._info = res._info.copy() … … 176 180 if fallback is not None: 177 181 res = fallback 178 182 else: 183 _translations_lock.release() 179 184 return gettext_module.NullTranslations() 180 185 _translations[lang] = res 186 _translations_lock.release() 181 187 return res 182 188 183 189 default_translation = _fetch(settings.LANGUAGE_CODE)