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 import re
30
31 from translate.storage import factory
32 from translate.misc.multistring import multistring
33
34 tw4winre = re.compile(r"\{0>.*?<\}\d{1,3}\{>(.*?)<0\}", re.M | re.S)
35
36
38 """cleans the targets in the given unit"""
39 if isinstance(unit.target, multistring):
40 strings = unit.target.strings
41 else:
42 strings = [unit.target]
43 for index, string in enumerate(strings):
44 string = string.replace("\par", "")
45 strings[index] = tw4winre.sub(r"\1", string)
46 if len(strings) == 1:
47 unit.target = strings[0]
48 else:
49 unit.target = strings
50
51
53 """cleans the given file"""
54 for unit in thefile.units:
55 cleanunit(unit)
56 return thefile
57
58
59 -def runclean(inputfile, outputfile, templatefile):
60 """reads in inputfile, cleans, writes to outputfile"""
61 fromfile = factory.getobject(inputfile)
62
63 cleanfile(fromfile)
64
65
66 outputfile.write(str(fromfile))
67 return True
68
69
71 from translate.convert import convert
72 formats = {"po": ("po", runclean), "xlf": ("xlf", runclean), None: ("po", runclean)}
73 parser = convert.ConvertOptionParser(formats, usetemplates=False, description=__doc__)
74 parser.run()
75
76
77 if __name__ == '__main__':
78 main()
79