From a4215712a7611c8f2e9d907e0cd9c734de14a8af Mon Sep 17 00:00:00 2001 From: thomasZen Date: Mon, 11 May 2020 15:55:14 +0200 Subject: Update tmx-extract.py to use python3 --- tmx-extract.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'tmx-extract.py') diff --git a/tmx-extract.py b/tmx-extract.py index 90a298a..e8ec959 100755 --- a/tmx-extract.py +++ b/tmx-extract.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 # # Adapted from Apertium # http://wiki.apertium.org/wiki/Tools_for_TMX @@ -54,23 +54,23 @@ class TMXHandler(ContentHandler): def endElement(self, name): if name == 'tu' and self.pair == self.cur_pair: for lang in self.cur_pair: - self.files[lang].write(self.seg[lang].encode('utf-8').strip()+"\n") + self.files[lang].write("{}\n".format(self.seg[lang].strip())) -parser = make_parser() -if len(sys.argv) < 3: - print 'Usage: tmx-extract.py ' - print '' - sys.exit(-1) +if __name__ == "__main__": + parser = make_parser() -sfile = open(sys.argv[1]+"."+sys.argv[2], 'w+') -tfile = open(sys.argv[1]+"."+sys.argv[3], 'w+') -curHandler = TMXHandler(sys.argv[2], sys.argv[3], sfile, tfile) + if len(sys.argv) < 3: + print('Usage: tmx-extract.py ') + print('') + sys.exit(-1) -parser.setContentHandler(curHandler) + sfile_path = sys.argv[1] + "." + sys.argv[2] + tfile_path = sys.argv[1] + "." + sys.argv[3] -parser.parse(open(sys.argv[1])) - -sfile.close() -tfile.close() + with open(sfile_path, 'w+') as sfile, open(tfile_path, 'w+') as tfile: + curHandler = TMXHandler(sys.argv[2], sys.argv[3], sfile, tfile) + parser.setContentHandler(curHandler) + with open(sys.argv[1], 'r') as tmx_file: + parser.parse(tmx_file) -- cgit v1.2.3 From 4732fb3be94ba3f88b18295cf1c00e8c616eec73 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Tue, 30 Jun 2020 12:28:21 +0200 Subject: tmx-extract.py: replace newlines --- tmx-extract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tmx-extract.py') diff --git a/tmx-extract.py b/tmx-extract.py index e8ec959..00f18f5 100755 --- a/tmx-extract.py +++ b/tmx-extract.py @@ -54,7 +54,7 @@ class TMXHandler(ContentHandler): def endElement(self, name): if name == 'tu' and self.pair == self.cur_pair: for lang in self.cur_pair: - self.files[lang].write("{}\n".format(self.seg[lang].strip())) + self.files[lang].write("{}\n".format(self.seg[lang].replace("\n", " ").strip())) if __name__ == "__main__": -- cgit v1.2.3