Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(64)

Side by Side Diff: translate/storage/pocommon.py

Issue 4: Format knowledge in format classes SVN Base: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/
Patch Set: Second try Created 1 year, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 # 3 #
4 # Copyright 2002-2007 Zuza Software Foundation 4 # Copyright 2002-2007 Zuza Software Foundation
5 # 5 #
6 # This file is part of translate. 6 # This file is part of translate.
7 # 7 #
8 # translate is free software; you can redistribute it and/or modify 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 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 10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version. 11 # (at your option) any later version.
12 # 12 #
13 # translate is distributed in the hope that it will be useful, 13 # translate is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details. 16 # GNU General Public License for more details.
17 # 17 #
18 # You should have received a copy of the GNU General Public License 18 # You should have received a copy of the GNU General Public License
19 # along with translate; if not, write to the Free Software 19 # along with translate; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 21
22 from translate.storage import base 22 from translate.storage import base
23 from translate.storage import poheader 23 from translate.storage import poheader
24 24
25 class pounit(base.TranslationUnit): 25 class pounit(base.TranslationUnit):
26 26
27 def adderror(self, errorname, errortext): 27 def adderror(self, errorname, errortext):
28 """Adds an error message to this unit.""" 28 """Adds an error message to this unit."""
29 text = u'(pofilter) %s: %s' % (errorname, errortext) 29 text = u'(pofilter) %s: %s' % (errorname, errortext)
30 # Don't add the same error twice: 30 # Don't add the same error twice:
31 if text not in self.getnotes(origin='translator'): 31 if text not in self.getnotes(origin='translator'):
32 self.addnote(text, origin="translator") 32 self.addnote(text, origin="translator")
33 33
34 def geterrors(self): 34 def geterrors(self):
35 """Get all error messages.""" 35 """Get all error messages."""
36 notes = self.getnotes(origin="translator").split('\n') 36 notes = self.getnotes(origin="translator").split('\n')
37 errordict = {} 37 errordict = {}
38 for note in notes: 38 for note in notes:
39 if '(pofilter) ' in note: 39 if '(pofilter) ' in note:
40 error = note.replace('(pofilter) ', '') 40 error = note.replace('(pofilter) ', '')
41 errorname, errortext = error.split(': ') 41 errorname, errortext = error.split(': ')
42 errordict[errorname] = errortext 42 errordict[errorname] = errortext
43 return errordict 43 return errordict
44 44
45 def markreviewneeded(self, needsreview=True, explanation=None): 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.""" 46 """Marks the unit to indicate whether it needs review. Adds an optional explanation as a note."""
47 if needsreview: 47 if needsreview:
48 reviewnote = "(review)" 48 reviewnote = "(review)"
49 if explanation: 49 if explanation:
50 reviewnote += " " + explanation 50 reviewnote += " " + explanation
51 self.addnote(reviewnote, origin="translator") 51 self.addnote(reviewnote, origin="translator")
52 else: 52 else:
53 # Strip (review) notes. 53 # Strip (review) notes.
54 notestring = self.getnotes(origin="translator") 54 notestring = self.getnotes(origin="translator")
55 notes = notestring.split('\n') 55 notes = notestring.split('\n')
56 newnotes = [] 56 newnotes = []
57 for note in notes: 57 for note in notes:
58 if not '(review)' in note: 58 if not '(review)' in note:
59 newnotes.append(note) 59 newnotes.append(note)
60 newnotes = '\n'.join(newnotes) 60 newnotes = '\n'.join(newnotes)
61 self.removenotes() 61 self.removenotes()
62 self.addnote(newnotes, origin="translator") 62 self.addnote(newnotes, origin="translator")
63 63
64 class pofile(base.TranslationStore, poheader.poheader): 64 class pofile(base.TranslationStore, poheader.poheader):
65
66 name = "Gettext PO file"
dwaynebailey 2008/07/11 09:52:20 Some thought needs to go into what to do with temp
67 extension = ("*.po", "*.pot")
68 mimetype = ("application/x-gettext-catalog", )
dwaynebailey 2008/07/11 09:52:20 This is the wrong mimetype I think it is meant to
65 69
66 def makeheader(self, **kwargs): 70 def makeheader(self, **kwargs):
67 """create a header for the given filename. arguments are specially handl ed, kwargs added as key: value 71 """create a header for the given filename. arguments are specially handl ed, kwargs added as key: value
68 pot_creation_date can be None (current date) or a value (datetime or str ing) 72 pot_creation_date can be None (current date) or a value (datetime or str ing)
69 po_revision_date can be None (form), False (=pot_creation_date), True (= now), or a value (datetime or string)""" 73 po_revision_date can be None (form), False (=pot_creation_date), True (= now), or a value (datetime or string)"""
70 74
71 headerpo = self.UnitClass(encoding=self._encoding) 75 headerpo = self.UnitClass(encoding=self._encoding)
72 headerpo.markfuzzy() 76 headerpo.markfuzzy()
73 headerpo.source = "" 77 headerpo.source = ""
74 headeritems = self.makeheaderdict(**kwargs) 78 headeritems = self.makeheaderdict(**kwargs)
75 headervalue = "" 79 headervalue = ""
76 for (key, value) in headeritems.items(): 80 for (key, value) in headeritems.items():
77 headervalue += "%s: %s\n" % (key, value) 81 headervalue += "%s: %s\n" % (key, value)
78 headerpo.target = headervalue 82 headerpo.target = headervalue
79 return headerpo 83 return headerpo
OLDNEW

Powered by Google App Engine
This is Rietveld r159