summaryrefslogtreecommitdiffstats
path: root/pyload/utils/__init__.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-12-12 00:52:46 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-12-12 00:52:46 +0100
commit08b7c5a163adb6ad053ea3284fae2cae69e4be3f (patch)
treead59db622dacdfc61162ce42ed7eb7d415e08b52 /pyload/utils/__init__.py
parentSpare code fixes (2) (diff)
downloadpyload-08b7c5a163adb6ad053ea3284fae2cae69e4be3f.tar.xz
New Setup
Diffstat (limited to 'pyload/utils/__init__.py')
-rw-r--r--pyload/utils/__init__.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py
index 39a3ae751..a4e98ac5c 100644
--- a/pyload/utils/__init__.py
+++ b/pyload/utils/__init__.py
@@ -3,13 +3,15 @@
""" Store all useful functions here """
import os
+import re
import sys
import time
-import re
+
+from gettext import gettext
+from htmlentitydefs import name2codepoint
from os.path import join
from string import maketrans
from urllib import unquote
-from htmlentitydefs import name2codepoint
# abstraction layer for json operations
try:
@@ -245,3 +247,16 @@ def html_unescape(text):
def versiontuple(v): #: By kindall (http://stackoverflow.com/a/11887825)
return tuple(map(int, (v.split("."))))
+
+
+def load_translation(name, locale, default="en"):
+ """ Load language and return its translation object or None """
+ try:
+ gettext.setpaths([path.join(os.sep, "usr", "share", "pyload", "locale"), None])
+ translation = gettext.translation(name, self.path("locale"),
+ languages=[locale, default], fallback=True)
+ except Exception:
+ return None
+ else:
+ translation.install(True)
+ return translation