2 # -*- coding: utf-8 -*-
4 # Copyright 2002-2007 Zuza Software Foundation
6 # This file is part of translate.
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.
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.
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
22 from translate
.storage
import base
23 from translate
.storage
import poheader
25 class pounit(base
.TranslationUnit
):
27 def adderror(self
, errorname
, errortext
):
28 """Adds an error message to this unit."""
29 text
= u
'(pofilter) %s: %s' % (errorname
, errortext
)
30 # Don't add the same error twice:
31 if text
not in self
.getnotes(origin
='translator'):
32 self
.addnote(text
, origin
="translator")
35 """Get all error messages."""
36 notes
= self
.getnotes(origin
="translator").split('\n')
39 if '(pofilter) ' in note
:
40 error
= note
.replace('(pofilter) ', '')
41 errorname
, errortext
= error
.split(': ')
42 errordict
[errorname
] = errortext
45 def markreviewneeded(self
, needsreview
=True, explanation
=None):
46 """Marks the unit to indicate whether it needs review. Adds an optional explanation as a note."""
48 reviewnote
= "(review)"
50 reviewnote
+= " " + explanation
51 self
.addnote(reviewnote
, origin
="translator")
53 # Strip (review) notes.
54 notestring
= self
.getnotes(origin
="translator")
55 notes
= notestring
.split('\n')
58 if not '(review)' in note
:
60 newnotes
= '\n'.join(newnotes
)
62 self
.addnote(newnotes
, origin
="translator")
64 class pofile(base
.TranslationStore
, poheader
.poheader
):
66 def makeheader(self
, **kwargs
):
67 """create a header for the given filename. arguments are specially handled, kwargs added as key: value
68 pot_creation_date can be None (current date) or a value (datetime or string)
69 po_revision_date can be None (form), False (=pot_creation_date), True (=now), or a value (datetime or string)"""
71 headerpo
= self
.UnitClass(encoding
=self
._encoding
)
74 headeritems
= self
.makeheaderdict(**kwargs
)
76 for (key
, value
) in headeritems
.items():
77 headervalue
+= "%s: %s\n" % (key
, value
)
78 headerpo
.target
= headervalue