import gettext
import pkg_resources
+import threading
#############################
# A WorkBenchManager
workbench_manager = None
+# A thread-local scope
+thread_scope = threading.local()
+
# gettext
-translations = gettext.find(
+thread_scope.translations = gettext.find(
'mediagoblin',
pkg_resources.resource_filename(
'mediagoblin', 'translations'), ['en'])
extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape'])
template_env.install_gettext_callables(
- mg_globals.translations.ugettext,
- mg_globals.translations.ungettext)
+ mg_globals.thread_scope.translations.ugettext,
+ mg_globals.thread_scope.translations.ungettext)
# All templates will know how to ...
# ... fetch all waiting messages and remove them from the queue
# TODO: fallback nicely on translations from pt_PT to pt if not
# available, etc.
- if SETUP_GETTEXTS.has_key(locale):
+ if locale in SETUP_GETTEXTS:
this_gettext = SETUP_GETTEXTS[locale]
else:
this_gettext = gettext.translation(
if exists(locale):
SETUP_GETTEXTS[locale] = this_gettext
- mg_globals.setup_globals(
- translations=this_gettext)
+ mg_globals.thread_scope.translations = this_gettext
# Force en to be setup before anything else so that
The reason we can't have a global ugettext method is because
mg_globals gets swapped out by the application per-request.
"""
- return mg_globals.translations.ugettext(
+ return mg_globals.thread_scope.translations.ugettext(
*args, **kwargs)
The reason we can't have a global ngettext method is because
mg_globals gets swapped out by the application per-request.
"""
- return mg_globals.translations.ngettext(
+ return mg_globals.thread_scope.translations.ngettext(
*args, **kwargs)