Package translate :: Package storage :: Module pocommon
[hide private]
[frames] | no frames]

Source Code for Module translate.storage.pocommon

 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   
25 -class pounit(base.TranslationUnit):
26
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")
33
34 - def geterrors(self):
35 """Get all error messages.""" 36 notes = self.getnotes(origin="translator").split('\n') 37 errordict = {} 38 for note in notes: 39 if '(pofilter) ' in note: 40 error = note.replace('(pofilter) ', '') 41 errorname, errortext = error.split(': ') 42 errordict[errorname] = errortext 43 return errordict
44
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.""" 47 if needsreview: 48 reviewnote = "(review)" 49 if explanation: 50 reviewnote += " " + explanation 51 self.addnote(reviewnote, origin="translator") 52 else: 53 # Strip (review) notes. 54 notestring = self.getnotes(origin="translator") 55 notes = notestring.split('\n') 56 newnotes = [] 57 for note in notes: 58 if not '(review)' in note: 59 newnotes.append(note) 60 newnotes = '\n'.join(newnotes) 61 self.removenotes() 62 self.addnote(newnotes, origin="translator")
63
64 -class pofile(base.TranslationStore, poheader.poheader):
65 Name = "Gettext PO file" 66 Mimetypes = ["text/x-gettext-catalog", "text/x-po", "text/x-pot"] 67 Extensions = ["po", "pot"] 68
69 - def makeheader(self, **kwargs):
70 """create a header for the given filename. arguments are specially handled, kwargs added as key: value 71 pot_creation_date can be None (current date) or a value (datetime or string) 72 po_revision_date can be None (form), False (=pot_creation_date), True (=now), or a value (datetime or string)""" 73 74 headerpo = self.UnitClass(encoding=self._encoding) 75 headerpo.markfuzzy() 76 headerpo.source = "" 77 headeritems = self.makeheaderdict(**kwargs) 78 headervalue = "" 79 for (key, value) in headeritems.items(): 80 headervalue += "%s: %s\n" % (key, value) 81 headerpo.target = headervalue 82 return headerpo
83