summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/request.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/ipalib/request.py b/ipalib/request.py
index 3e4b2798e..545ebc540 100644
--- a/ipalib/request.py
+++ b/ipalib/request.py
@@ -28,15 +28,10 @@ import gettext
from constants import OVERRIDE_ERROR
-# Thread-local storage of most per-request contextrmation
+# Thread-local storage of most per-request information
context = threading.local()
-# Thread-local storage of gettext.Translations instances (one per gettext
-# domain):
-translations = threading.local()
-
-
def set_languages(*languages):
if hasattr(context, 'languages'):
raise StandardError(
@@ -46,3 +41,17 @@ def set_languages(*languages):
languages = locale.getdefaultlocale()[:1]
context.languages = languages
assert type(context.languages) is tuple
+
+
+def create_translation(domain, localedir, *languages):
+ if hasattr(context, 'gettext') or hasattr(context, 'ngettext'):
+ raise StandardError(
+ 'create_translation() already called in thread %r' %
+ threading.currentThread().getName()
+ )
+ set_languages(*languages)
+ translation = gettext.translation(domain,
+ localedir=localedir, languages=context.languages, fallback=True
+ )
+ context.gettext = translation.ugettext
+ context.ngettext = translation.ungettext