Skip to content

Commit 99bb5b2

Browse files
committed
FEATURE: Automate the update/merge of the .po files
1 parent 788ca28 commit 99bb5b2

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

.github/workflows/i18n-extract.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ jobs:
2323
with:
2424
python-version: '3.x'
2525

26-
- name: Install requirements
26+
- name: Install apt gettext package
27+
run: |
28+
sudo apt-get update
29+
sudo apt-get install -y gettext
30+
31+
- name: Install python-gettext requirement
2732
run: |
2833
python -m pip install --upgrade pip python-gettext
2934
@@ -43,9 +48,20 @@ jobs:
4348
if [ $CHANGED_LINES -gt 4 ]; then
4449
git commit -m "CHORE: Extracted i18n strings to $PYGETTEXT_LOCALEDIR/$PYGETTEXT_DOMAIN.pot"
4550
git push
51+
python merge_pot_file.py
4652
else
4753
echo "Not enough changes to commit (only $CHANGED_LINES lines changed)"
4854
fi
4955
else
5056
echo "No changes to commit"
5157
fi
58+
59+
- name: Create Pull Request
60+
uses: peter-evans/create-pull-request@v5
61+
with:
62+
token: ${{ secrets.GITHUB_TOKEN }}
63+
branch: merge-i18n-po-strings
64+
title: "chore(deps): merge translation string(s) to existing .po files"
65+
commit-message: "chore(deps): merge translation string(s) to existing .po files"
66+
body: |
67+
Update .po files with string(s) from the .pot file

merge_pot_file.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)