summaryrefslogtreecommitdiffstats
path: root/module/common/pylgettext.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-12-07 19:22:02 +0100
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-12-07 19:22:02 +0100
commitb575e03d6621cd236df7de3879507efa38ad16b8 (patch)
treeb454c2336f6dbc2048863b2457af2810a0ea1cc3 /module/common/pylgettext.py
parentnew l18n files, closed #448 (diff)
downloadpyload-b575e03d6621cd236df7de3879507efa38ad16b8.tar.xz
closed #436
Diffstat (limited to 'module/common/pylgettext.py')
-rw-r--r--module/common/pylgettext.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/module/common/pylgettext.py b/module/common/pylgettext.py
new file mode 100644
index 000000000..ae6d39325
--- /dev/null
+++ b/module/common/pylgettext.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from gettext import *
+
+_searchdirs = None
+
+origfind = find
+
+def setpaths(pathlist):
+ global _searchdirs
+ if isinstance(pathlist, list):
+ _searchdirs = pathlist
+ else:
+ _searchdirs = list(pathlist)
+
+
+def addpath(path):
+ global _searchdirs
+ if _searchdirs is None:
+ _searchdirs = list(path)
+ else:
+ if path not in _searchdirs:
+ _searchdirs.append(path)
+
+
+def delpath(path):
+ global _searchdirs
+ if _searchdirs is not None:
+ if path in _searchdirs:
+ _searchdirs.remove(path)
+
+
+def clearpath():
+ global _searchdirs
+ if _searchdirs is not None:
+ _searchdirs = None
+
+
+def find(domain, localedir=None, languages=None, all=False):
+ if _searchdirs is None:
+ return origfind(domain, localedir, languages, all)
+ searches = [localedir] + _searchdirs
+ results = list()
+ for dir in searches:
+ res = origfind(domain, dir, languages, all)
+ if all is False:
+ results.append(res)
+ else:
+ results.extend(res)
+ if all is False:
+ results = filter(lambda x: x is not None, results)
+ if len(results) == 0:
+ return None
+ else:
+ return results[0]
+ else:
+ return results
+
+#Is there a smarter/cleaner pythonic way for this?
+translation.__globals__['find'] = find
+