|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +""" |
| 4 | +Merge .pot file strings into existing .po files. |
| 5 | +
|
| 6 | +This file is part of Ardupilot methodic configurator. https://github.com/ArduPilot/MethodicConfigurator |
| 7 | +
|
| 8 | +SPDX-FileCopyrightText: 2024-2025 Amilcar do Carmo Lucas <[email protected]> |
| 9 | +
|
| 10 | +SPDX-License-Identifier: GPL-3.0-or-later |
| 11 | +""" |
| 12 | + |
| 13 | +import logging |
| 14 | +import os |
| 15 | +import subprocess |
| 16 | +from platform import system as platform_system |
| 17 | + |
| 18 | + |
| 19 | +def process_locale_directory(locale_dir: str, pot_file: str) -> None: |
| 20 | + """Process a single locale directory.""" |
| 21 | + po_file = os.path.join(locale_dir, "ardupilot_methodic_configurator.po") |
| 22 | + |
| 23 | + try: |
| 24 | + # Run msgfmt command |
| 25 | + exe = "C:\\Program Files\\gettext-iconv\\bin\\msgmerge.exe" if platform_system() == "Windows" else "msgmerge" |
| 26 | + cmd = [exe, "--update", "--no-fuzzy-matching", po_file, pot_file] |
| 27 | + # pylint: disable=duplicate-code |
| 28 | + subprocess.run(cmd, check=True, capture_output=True, text=True) # noqa: S603 |
| 29 | + msg = f"Successfully processed {locale_dir}" |
| 30 | + logging.info(msg) |
| 31 | + except subprocess.CalledProcessError as e: |
| 32 | + msg = f"Error processing {locale_dir}: {e}" |
| 33 | + logging.error(msg) |
| 34 | + |
| 35 | + |
| 36 | +def main() -> None: |
| 37 | + logging.basicConfig(level="INFO", format="%(asctime)s - %(levelname)s - %(message)s") |
| 38 | + # pylint: enable=duplicate-code |
| 39 | + |
| 40 | + pot_file = os.path.join("ardupilot_methodic_configurator", "locale", "ardupilot_methodic_configurator.pot") |
| 41 | + |
| 42 | + # Walk through all locale directories |
| 43 | + for root, dirs, _files in os.walk(os.path.join("ardupilot_methodic_configurator", "locale")): |
| 44 | + if "LC_MESSAGES" in dirs: |
| 45 | + locale_dir = os.path.join(root, "LC_MESSAGES") |
| 46 | + process_locale_directory(locale_dir, pot_file) |
| 47 | + |
| 48 | + |
| 49 | +if __name__ == "__main__": |
| 50 | + main() |
0 commit comments