Skip to content

tmx_switch

main()

Switch languages of the given TMX file.

Source code in corpustools/tmx_switch.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def main():
    """Switch languages of the given TMX file."""
    args = parse_options()

    old_xml = etree.parse(args.tmx_file)
    old_tmx_root = old_xml.getroot()
    header = old_tmx_root.find("header")
    if header is None:
        raise SystemExit("No <header> element found in the TMX file.")
    set_metadata(header, old_tmx_root)

    new_tmx_root = etree.Element("tmx")
    new_tmx_root.append(header)

    make_body(new_tmx_root, old_tmx_root)

    switched_file = Path("switched.tmx")
    switched_file.write_bytes(
        etree.tostring(
            new_tmx_root, pretty_print=True, encoding="UTF-8"
        )
    )

parse_options()

Parse the given options.

Source code in corpustools/tmx_switch.py
 9
10
11
12
13
14
15
16
17
18
19
20
def parse_options():
    """Parse the given options."""
    parser = argparse.ArgumentParser(
        parents=[argparse_version.parser], description="Analyse files in parallel."
    )

    parser.add_argument(
        "tmx_file",
        help="file where language switches should be made",
    )

    return parser.parse_args()