#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2013-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only
"""
This script walks over all po files in a given directory and its subfolders.
It fills all msgid strings with the same content as the corresponding msgid,
prepeding it with the character sequence '!TR!'.
It is useful for visual quick testing of translation coverage and po file
generation.
"""

import argparse
import os

import polib


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description=__doc__, usage='%(prog)s [directory]')
    parser.add_argument('directory', help="Base directory for recursive search")
    args = parser.parse_args()
    return args


def process(po_dir: str) -> None:
    for _dir, _dns, fns in os.walk(os.path.abspath(po_dir)):
        for po_file in fns:
            if not po_file.endswith('.po'):
                continue
            po = polib.pofile(os.path.join(_dir, po_file))
            for entry in po:
                if entry.msgid == '':
                    continue
                entry.msgstr = "!TR! " + entry.msgid
            po.save(os.path.join(_dir, po_file))


def main() -> None:
    args = parse_args()
    process(args.directory)


if __name__ == '__main__':
    main()
