forked from ArduPilot/MethodicConfigurator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_mo_files.py
More file actions
executable file
·60 lines (45 loc) · 1.79 KB
/
create_mo_files.py
File metadata and controls
executable file
·60 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""
Create .mo files from the .po files.
This file is part of ArduPilot Methodic Configurator. https://github.com/ArduPilot/MethodicConfigurator
SPDX-FileCopyrightText: 2024-2026 Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
SPDX-License-Identifier: GPL-3.0-or-later
"""
import logging
import os
import subprocess
import sys
from platform import system as platform_system
def process_locale_directory(locale_dir: str) -> bool:
"""
Process a single locale directory.
Returns True if successful, False otherwise.
"""
po_file = os.path.join(locale_dir, "ardupilot_methodic_configurator.po")
mo_file = os.path.join(locale_dir, "ardupilot_methodic_configurator.mo")
try:
# Run msgfmt command
exe = "C:\\Program Files\\gettext-iconv\\bin\\msgfmt.exe" if platform_system() == "Windows" else "msgfmt"
cmd = [exe, "-o", mo_file, po_file]
subprocess.run(cmd, check=True, capture_output=True, text=True) # noqa: S603
msg = f"Successfully processed {locale_dir}"
logging.info(msg)
return True
except subprocess.CalledProcessError as e:
msg = f"Error processing {locale_dir}: {e}"
logging.error(msg)
return False
def main() -> None:
logging.basicConfig(level="INFO", format="%(asctime)s - %(levelname)s - %(message)s")
errors = 0
# Walk through all locale directories
for root, dirs, _files in os.walk(os.path.join("ardupilot_methodic_configurator", "locale")):
if "LC_MESSAGES" in dirs:
locale_dir = os.path.join(root, "LC_MESSAGES")
if not process_locale_directory(locale_dir):
errors += 1
if errors > 0:
logging.error("Failed to compile %d locale(s)", errors)
sys.exit(1)
if __name__ == "__main__":
main()