1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import re
23
24 from translate.storage import base
25 from translate.storage import poheader
26 from translate.storage.workflow import StateEnum as state
27
28 msgid_comment_re = re.compile("_: (.*?)\n")
29
30
40
41
42 -class pounit(base.TranslationUnit):
43 S_OBSOLETE = state.OBSOLETE
44 S_UNTRANSLATED = state.EMPTY
45 S_FUZZY = state.NEEDS_WORK
46 S_TRANSLATED = state.UNREVIEWED
47
48 STATE = {
49 S_OBSOLETE: (state.OBSOLETE, state.EMPTY),
50 S_UNTRANSLATED: (state.EMPTY, state.NEEDS_WORK),
51 S_FUZZY: (state.NEEDS_WORK, state.UNREVIEWED),
52 S_TRANSLATED: (state.UNREVIEWED, state.MAX),
53 }
54
55 - def adderror(self, errorname, errortext):
56 """Adds an error message to this unit."""
57 text = u'(pofilter) %s: %s' % (errorname, errortext)
58
59 if text not in self.getnotes(origin='translator'):
60 self.addnote(text, origin="translator")
61
63 """Get all error messages."""
64 notes = self.getnotes(origin="translator").split('\n')
65 errordict = {}
66 for note in notes:
67 if '(pofilter) ' in note:
68 error = note.replace('(pofilter) ', '')
69 errorname, errortext = error.split(': ', 1)
70 errordict[errorname] = errortext
71 return errordict
72
74 """Marks the unit to indicate whether it needs review. Adds an optional explanation as a note."""
75 if needsreview:
76 reviewnote = "(review)"
77 if explanation:
78 reviewnote += " " + explanation
79 self.addnote(reviewnote, origin="translator")
80 else:
81
82 notestring = self.getnotes(origin="translator")
83 notes = notestring.split('\n')
84 newnotes = []
85 for note in notes:
86 if not '(review)' in note:
87 newnotes.append(note)
88 newnotes = '\n'.join(newnotes)
89 self.removenotes()
90 self.addnote(newnotes, origin="translator")
91
94
97
100
103
106
109
117
120
125
127 raise NotImplementedError()
128
133
134
136 """Tests whether the given encoding is known in the python runtime, or returns utf-8.
137 This function is used to ensure that a valid encoding is always used."""
138 if encoding == "CHARSET" or encoding == None:
139 return 'utf-8'
140 return encoding
141
142
143
144
145
146
147
148
149
150 -class pofile(poheader.poheader, base.TranslationStore):
151 Name = _("Gettext PO file")
152 Mimetypes = ["text/x-gettext-catalog", "text/x-gettext-translation", "text/x-po", "text/x-pot"]
153 Extensions = ["po", "pot"]
154
155 - def __init__(self, inputfile=None, encoding=None):
164