From 8805e95ae94d798c6441f7e1b72c90e049563f17 Mon Sep 17 00:00:00 2001 From: pks Date: Mon, 8 Apr 2024 09:08:36 +0000 Subject: bitext2tmx.py --- bitext2tmx.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 bitext2tmx.py diff --git a/bitext2tmx.py b/bitext2tmx.py new file mode 100755 index 0000000..1cdc4b3 --- /dev/null +++ b/bitext2tmx.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import sys +from xml.sax.saxutils import escape + + +if __name__ == "__main__": + prefix = """ +
+ """ + + src_file = open(sys.argv[1], "r") + tgt_file = open(sys.argv[2], "r") + + src_lang = sys.argv[1].split(".")[-1] + tgt_lang = sys.argv[2].split(".")[-1] + + tus = [] + for src_line, tgt_line in zip(src_file.readlines(), tgt_file.readlines()): + src_line = src_line.rstrip("\n") + tgt_line = tgt_line.rstrip("\n") + tus.append(f""" + + + {escape(src_line)} + + + {escape(tgt_line)} + + """) + + suffix = """ +""" + + complete = "\n".join([prefix] + tus + [suffix]) + + print(complete) -- cgit v1.2.3