Repository navigation
Expand file tree
/
Copy pathpylgettext.py
More file actions
61 lines (48 loc) · 1.36 KB
/
Copy pathpylgettext.py
File metadata and controls
61 lines (48 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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.func_globals['find'] = find