| Home | Trees | Indices | Help |
|
|---|
|
|
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright 2002-2007 Zuza Software Foundation
5 #
6 # This file is part of translate.
7 #
8 # translate is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # translate is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with translate; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 from translate.storage import base
23 from translate.storage import poheader
24 from translate.storage.workflow import StateEnum as state
25
26 import re
27
28 msgid_comment_re = re.compile("_: (.*?)\n")
29
31 """The one definitive way to extract a msgid comment out of an unescaped
32 unicode string that might contain it.
33
34 @rtype: unicode"""
35 msgidcomment = msgid_comment_re.match(text)
36 if msgidcomment:
37 return msgidcomment.group(1)
38 return u""
39
40
42 S_OBSOLETE = state.OBSOLETE
43 S_UNTRANSLATED = state.EMPTY
44 S_FUZZY = state.NEEDS_WORK
45 S_TRANSLATED = state.UNREVIEWED
46
47 STATE = {
48 S_OBSOLETE: (state.OBSOLETE, state.EMPTY),
49 S_UNTRANSLATED: (state.EMPTY, state.NEEDS_WORK),
50 S_FUZZY: (state.NEEDS_WORK, state.UNREVIEWED),
51 S_TRANSLATED: (state.UNREVIEWED, state.MAX),
52 }
53
55 """Adds an error message to this unit."""
56 text = u'(pofilter) %s: %s' % (errorname, errortext)
57 # Don't add the same error twice:
58 if text not in self.getnotes(origin='translator'):
59 self.addnote(text, origin="translator")
60
62 """Get all error messages."""
63 notes = self.getnotes(origin="translator").split('\n')
64 errordict = {}
65 for note in notes:
66 if '(pofilter) ' in note:
67 error = note.replace('(pofilter) ', '')
68 errorname, errortext = error.split(': ', 1)
69 errordict[errorname] = errortext
70 return errordict
71
73 """Marks the unit to indicate whether it needs review. Adds an optional explanation as a note."""
74 if needsreview:
75 reviewnote = "(review)"
76 if explanation:
77 reviewnote += " " + explanation
78 self.addnote(reviewnote, origin="translator")
79 else:
80 # Strip (review) notes.
81 notestring = self.getnotes(origin="translator")
82 notes = notestring.split('\n')
83 newnotes = []
84 for note in notes:
85 if not '(review)' in note:
86 newnotes.append(note)
87 newnotes = '\n'.join(newnotes)
88 self.removenotes()
89 self.addnote(newnotes, origin="translator")
90
93
96
99
102
105
108
110 if present:
111 self.set_state_n(self.STATE[self.S_FUZZY][0])
112 elif self.gettarget():
113 self.set_state_n(self.STATE[self.S_TRANSLATED][0])
114 else:
115 self.set_state_n(self.STATE[self.S_UNTRANSLATED][0])
116
119
121 self.set_state_n(self.STATE[self.S_TRANSLATED][0])
122 if not self.gettarget():
123 self.set_state_n(self.STATE[self.S_UNTRANSLATED][0])
124
127
132
133
135 """Tests whether the given encoding is known in the python runtime, or returns utf-8.
136 This function is used to ensure that a valid encoding is always used."""
137 if encoding == "CHARSET" or encoding == None:
138 return 'utf-8'
139 return encoding
140 # if encoding is None: return False
141 # return True
142 # try:
143 # tuple = codecs.lookup(encoding)
144 # except LookupError:
145 # return False
146 # return True
147
149 Name = _("Gettext PO file") # pylint: disable-msg=E0602
150 Mimetypes = ["text/x-gettext-catalog", "text/x-gettext-translation", "text/x-po", "text/x-pot"]
151 Extensions = ["po", "pot"]
152
154 super(pofile, self).__init__(unitclass=self.UnitClass)
155 self.units = []
156 self.filename = ''
157 self._encoding = encodingToUse(encoding)
158 if inputfile is not None:
159 self.parse(inputfile)
160 else:
161 self.init_headers()
162
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Aug 17 15:50:17 2010 | http://epydoc.sourceforge.net |