1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """Perform quality checks on Gettext PO, XLIFF and TMX localization files
22
23 Snippet files whenever a test fails. These can be examined, corrected and
24 merged back into the originals using pomerge
25
26 See: http://translate.sourceforge.net/wiki/toolkit/pofilter for examples and
27 usage instructions and http://translate.sourceforge.net/wiki/toolkit/pofilter_tests
28 for full descriptions of all tests
29 """
30
31 from translate.storage import factory
32 from translate.storage.poheader import poheader
33 from translate.filters import checks
34 from translate.filters import autocorrect
35 from translate.misc import optrecurse
36
37 import os
38
40 - def __init__(self, options, checkerclasses=None, checkerconfig=None):
52
54 """lists the docs for filters available on checker..."""
55 filterdict = self.checker.getfilters()
56 filterdocs = ["%s\t%s" % (name, filterfunc.__doc__) for (name, filterfunc) in filterdict.iteritems()]
57 filterdocs.sort()
58 return "\n".join(filterdocs)
59
76
99
101 """a specialized Option Parser for filter tools..."""
103 """construct the specialized Option Parser"""
104 optrecurse.RecursiveOptionParser.__init__(self, formats)
105 self.set_usage()
106 self.add_option("-l", "--listfilters", action="callback", dest='listfilters',
107 default=False, callback_kwargs={'dest_value': True},
108 callback=self.parse_noinput, help="list filters available")
109
114
153
154 -def runfilter(inputfile, outputfile, templatefile, checkfilter=None):
155 """reads in inputfile, filters using checkfilter, writes to outputfile"""
156 fromfile = factory.getobject(inputfile)
157 tofile = checkfilter.filterfile(fromfile)
158 if tofile.isempty():
159 return 0
160 outputfile.write(str(tofile))
161 return 1
162
164 formats = {"po":("po", runfilter), "pot":("pot", runfilter),
165 "xliff":("xliff", runfilter), "xlf":("xlf", runfilter),
166 "tmx":("tmx", runfilter),
167 None:("po", runfilter)}
168
169 parser = FilterOptionParser(formats)
170 parser.add_option("", "--review", dest="includereview",
171 action="store_true", default=True,
172 help="include units marked for review (default)")
173 parser.add_option("", "--noreview", dest="includereview",
174 action="store_false", default=True,
175 help="exclude units marked for review")
176 parser.add_option("", "--fuzzy", dest="includefuzzy",
177 action="store_true", default=True,
178 help="include units marked fuzzy (default)")
179 parser.add_option("", "--nofuzzy", dest="includefuzzy",
180 action="store_false", default=True,
181 help="exclude units marked fuzzy")
182 parser.add_option("", "--nonotes", dest="addnotes",
183 action="store_false", default=True,
184 help="don't add notes about the errors")
185 parser.add_option("", "--autocorrect", dest="autocorrect",
186 action="store_true", default=False,
187 help="output automatic corrections where possible rather than describing issues")
188 parser.add_option("", "--language", dest="targetlanguage", default=None,
189 help="set target language code (e.g. af-ZA) [required for spell check and recommended in general]", metavar="LANG")
190 parser.add_option("", "--openoffice", dest="filterclass",
191 action="store_const", default=None, const=checks.OpenOfficeChecker,
192 help="use the standard checks for OpenOffice translations")
193 parser.add_option("", "--mozilla", dest="filterclass",
194 action="store_const", default=None, const=checks.MozillaChecker,
195 help="use the standard checks for Mozilla translations")
196 parser.add_option("", "--drupal", dest="filterclass",
197 action="store_const", default=None, const=checks.DrupalChecker,
198 help="use the standard checks for Drupal translations")
199 parser.add_option("", "--gnome", dest="filterclass",
200 action="store_const", default=None, const=checks.GnomeChecker,
201 help="use the standard checks for Gnome translations")
202 parser.add_option("", "--kde", dest="filterclass",
203 action="store_const", default=None, const=checks.KdeChecker,
204 help="use the standard checks for KDE translations")
205 parser.add_option("", "--wx", dest="filterclass",
206 action="store_const", default=None, const=checks.KdeChecker,
207 help="use the standard checks for wxWidgets translations")
208 parser.add_option("", "--excludefilter", dest="excludefilters",
209 action="append", default=[], type="string", metavar="FILTER",
210 help="don't use FILTER when filtering")
211 parser.add_option("-t", "--test", dest="limitfilters",
212 action="append", default=None, type="string", metavar="FILTER",
213 help="only use test FILTERs specified with this option when filtering")
214 parser.add_option("", "--notranslatefile", dest="notranslatefile",
215 default=None, type="string", metavar="FILE",
216 help="read list of untranslatable words from FILE (must not be translated)")
217 parser.add_option("", "--musttranslatefile", dest="musttranslatefile",
218 default=None, type="string", metavar="FILE",
219 help="read list of translatable words from FILE (must be translated)")
220 parser.add_option("", "--validcharsfile", dest="validcharsfile",
221 default=None, type="string", metavar="FILE",
222 help="read list of all valid characters from FILE (must be in UTF-8)")
223 parser.passthrough.append('checkfilter')
224 parser.description = __doc__
225 return parser
226
228 parser = cmdlineparser()
229 parser.run()
230
231 if __name__ == '__main__':
232 main()
233