-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathefilter.py
51 lines (46 loc) · 1.41 KB
/
efilter.py
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
from gettextformat import *
import os, datetime
# PO header
headerStr = """Project-Id-Version: %s
Report-Msgid-Bugs-To: %s
POT-Creation-Date: %s
PO-Revision-Date:
Last-Translator:
Language-Team:
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Language: %s"""
class Filter:
def __init__(self, basename, projectShort, project, bugsto):
self.basename = basename
self.projectShort = projectShort
self.project = project
self.poDate = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S+0000")
self.bugsto = bugsto
self.entries = {}
def consider(self, entry):
if self.isfiltered(entry):
self.entries[entry.contextString()] = entry
return True
return False
def sortEntries(self):
return sorted(self.entries)
def output(self, lang):
if not os.path.exists(self.projectShort): os.mkdir(self.projectShort)
if lang == 'en': fstr = "%s/%s.pot" % (self.projectShort, self.basename,)
else: fstr = "%s/%s_%s.po" % (self.projectShort, self.basename, lang)
f = open(fstr, 'w', encoding='utf-8')
entry = GetTextEntry()
entry.msgstr = headerStr % (self.project, self.bugsto, self.poDate, lang,)
f.write(str(entry))
skeys = self.sortEntries()
cpt = 0
for skey in skeys:
entry = self.entries[skey].asGettext(lang)
if lang == 'en' or entry.trString(lang) != '':
cpt += 1
f.write(str(entry))
f.close()
if cpt == 0: os.remove(fstr)
return cpt