summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-12-18 16:58:48 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-12-18 16:58:48 -0700
commit9a69adeef001ddd0c55513271cf02eedc0a9aef8 (patch)
treeea9ad448f6a82418f2e809242dd8c03fdecb9cf6 /ipalib
parentdc54dee622bf9ff95a59530423ac5caa01868373 (diff)
downloadfreeipa-9a69adeef001ddd0c55513271cf02eedc0a9aef8.tar.gz
freeipa-9a69adeef001ddd0c55513271cf02eedc0a9aef8.tar.xz
freeipa-9a69adeef001ddd0c55513271cf02eedc0a9aef8.zip
Added request.create_translation() function and corresponding unit tests
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