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
79
102
104 """a specialized Option Parser for filter tools..."""
106 """construct the specialized Option Parser"""
107 optrecurse.RecursiveOptionParser.__init__(self, formats)
108 self.set_usage()
109 self.add_option("-l", "--listfilters", action="callback", dest='listfilters',
110 default=False, callback_kwargs={'dest_value': True},
111 callback=self.parse_noinput, help="list filters available")
112
117
156
157 -def runfilter(inputfile, outputfile, templatefile, checkfilter=None):
158 """reads in inputfile, filters using checkfilter, writes to outputfile"""
159 fromfile = factory.getobject(inputfile)
160 tofile = checkfilter.filterfile(fromfile)
161 if tofile.isempty():
162 return 0
163 outputfile.write(str(tofile))
164 return 1
165
167 formats = {"po":("po", runfilter), "pot":("pot", runfilter),
168 "xliff":("xliff", runfilter), "xlf":("xlf", runfilter),
169 "tmx":("tmx", runfilter),
170 None:("po", runfilter)}
171
172 parser = FilterOptionParser(formats)
173 parser.add_option("", "--review", dest="includereview",
174 action="store_true", default=True,
175 help="include units marked for review (default)")
176 parser.add_option("", "--noreview", dest="includereview",
177 action="store_false", default=True,
178 help="exclude units marked for review")
179 parser.add_option("", "--fuzzy", dest="includefuzzy",
180 action="store_true", default=True,
181 help="include units marked fuzzy (default)")
182 parser.add_option("", "--nofuzzy", dest="includefuzzy",
183 action="store_false", default=True,
184 help="exclude units marked fuzzy")
185 parser.add_option("", "--nonotes", dest="addnotes",
186 action="store_false", default=True,
187 help="don't add notes about the errors")
188 parser.add_option("", "--autocorrect", dest="autocorrect",
189 action="store_true", default=False,
190 help="output automatic corrections where possible rather than describing issues")
191 parser.add_option("", "--language", dest="targetlanguage", default=None,
192 help="set target language code (e.g. af-ZA) [required for spell check and recommended in general]", metavar="LANG")
193 parser.add_option("", "--openoffice", dest="filterclass",
194 action="store_const", default=None, const=checks.OpenOfficeChecker,
195 help="use the standard checks for OpenOffice translations")
196 parser.add_option("", "--mozilla", dest="filterclass",
197 action="store_const", default=None, const=checks.MozillaChecker,
198 help="use the standard checks for Mozilla translations")
199 parser.add_option("", "--drupal", dest="filterclass",
200 action="store_const", default=None, const=checks.DrupalChecker,
201 help="use the standard checks for Drupal translations")
202 parser.add_option("", "--gnome", dest="filterclass",
203 action="store_const", default=None, const=checks.GnomeChecker,
204 help="use the standard checks for Gnome translations")
205 parser.add_option("", "--kde", dest="filterclass",
206 action="store_const", default=None, const=checks.KdeChecker,
207 help="use the standard checks for KDE translations")
208 parser.add_option("", "--wx", dest="filterclass",
209 action="store_const", default=None, const=checks.KdeChecker,
210 help="use the standard checks for wxWidgets translations")
211 parser.add_option("", "--excludefilter", dest="excludefilters",
212 action="append", default=[], type="string", metavar="FILTER",
213 help="don't use FILTER when filtering")
214 parser.add_option("-t", "--test", dest="limitfilters",
215 action="append", default=None, type="string", metavar="FILTER",
216 help="only use test FILTERs specified with this option when filtering")
217 parser.add_option("", "--notranslatefile", dest="notranslatefile",
218 default=None, type="string", metavar="FILE",
219 help="read list of untranslatable words from FILE (must not be translated)")
220 parser.add_option("", "--musttranslatefile", dest="musttranslatefile",
221 default=None, type="string", metavar="FILE",
222 help="read list of translatable words from FILE (must be translated)")
223 parser.add_option("", "--validcharsfile", dest="validcharsfile",
224 default=None, type="string", metavar="FILE",
225 help="read list of all valid characters from FILE (must be in UTF-8)")
226 parser.passthrough.append('checkfilter')
227 parser.description = __doc__
228 return parser
229
231 parser = cmdlineparser()
232 parser.run()
233
234 if __name__ == '__main__':
235 main()
236