--- a/app/django/utils/translation/trans_real.py Tue Oct 14 12:36:55 2008 +0000
+++ b/app/django/utils/translation/trans_real.py Tue Oct 14 16:00:59 2008 +0000
@@ -8,18 +8,7 @@
from cStringIO import StringIO
from django.utils.safestring import mark_safe, SafeData
-
-try:
- import threading
- hasThreads = True
-except ImportError:
- hasThreads = False
-
-if hasThreads:
- currentThread = threading.currentThread
-else:
- def currentThread():
- return 'no threading'
+from django.utils.thread_support import currentThread
# Translations are cached in a dictionary for every language+app tuple.
# The active translations are stored by threadid to make them thread local.
@@ -161,6 +150,15 @@
res = _translation(globalpath)
+ # We want to ensure that, for example, "en-gb" and "en-us" don't share
+ # the same translation object (thus, merging en-us with a local update
+ # doesn't affect en-gb), even though they will both use the core "en"
+ # translation. So we have to subvert Python's internal gettext caching.
+ base_lang = lambda x: x.split('-', 1)[0]
+ if base_lang(lang) in [base_lang(trans) for trans in _translations]:
+ res._info = res._info.copy()
+ res._catalog = res._catalog.copy()
+
def _merge(path):
t = _translation(path)
if t is not None:
@@ -246,7 +244,9 @@
True = right-to-left layout
"""
from django.conf import settings
- return get_language() in settings.LANGUAGES_BIDI
+
+ base_lang = get_language().split('-')[0]
+ return base_lang in settings.LANGUAGES_BIDI
def catalog():
"""
@@ -383,13 +383,13 @@
for lang, dirname in ((accept_lang, normalized),
(accept_lang.split('-')[0], normalized.split('_')[0])):
- if lang not in supported:
+ if lang.lower() not in supported:
continue
langfile = os.path.join(globalpath, dirname, 'LC_MESSAGES',
'django.mo')
if os.path.exists(langfile):
_accepted[normalized] = lang
- return lang
+ return lang
return settings.LANGUAGE_CODE