1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """Produces a clean file from an unclean file (Trados/Wordfast) by stripping
23 out the tw4win indicators.
24
25 This does not convert an RTF file to PO/XLIFF, but produces the target file
26 with only the target text in from a text version of the RTF.
27 """
28
29 from translate.storage import factory
30 from translate.misc.multistring import multistring
31 import re
32
33 tw4winre = re.compile(r"\{0>.*?<\}\d{1,3}\{>(.*?)<0\}", re.M | re.S)
34
36 """cleans the targets in the given unit"""
37
38
39
40 if isinstance(unit.target, multistring):
41 strings = unit.target.strings
42 else:
43 strings = [unit.target]
44 for index, string in enumerate(strings):
45 string = string.replace("\par", "")
46 strings[index] = tw4winre.sub(r"\1", string)
47 if len(strings) == 1:
48 unit.target = strings[0]
49 else:
50 unit.target = strings
51
53 """cleans the given file"""
54 for unit in thefile.units:
55 cleanunit(unit)
56 return thefile
57
58 -def runclean(inputfile, outputfile, templatefile):
59 """reads in inputfile, cleans, writes to outputfile"""
60 fromfile = factory.getobject(inputfile)
61
62 cleanfile(fromfile)
63
64
65 outputfile.write(str(fromfile))
66 return True
67
69 from translate.convert import convert
70 formats = {"po":("po", runclean), "xlf":("xlf", runclean), None:("po", runclean)}
71 parser = convert.ConvertOptionParser(formats, usetemplates=False, description=__doc__)
72 parser.run()
73
74 if __name__ == '__main__':
75 main()
76