CI: Create Automated Workflow for Translation Catalog Updates (#5959)

* CI: Automate translation catalog update

Signed-off-by: GitHub <noreply@github.com>

* Update triggers for localization workflow

Signed-off-by: GitHub <noreply@github.com>

* Rewrite HintsToPot with Python

* Disable scheduled workflow runs

* Apply formatting to HintsToPot.py

* Add missing exit() call
This commit is contained in:
ElectricalBoy 2024-07-29 21:38:10 +09:00 committed by GitHub
parent 7236d6cdbf
commit b40853af94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 77 additions and 2 deletions

View file

@ -0,0 +1,38 @@
name: Update Translation Catalog
on:
# schedule:
# - cron: 0 0 * * 1
workflow_dispatch:
jobs:
update_translation:
name: Update translation
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install gettext
run: |
sudo apt-get update
sudo apt-get install -y gettext
- name: Update translation catalog
run: |
./run_gettext.sh --full
git add localization/i18n/*
- name: Commit translation catalog updates
uses: qoomon/actions--create-commit@v1
id: commit
with:
message: Update translation catalog
skip-empty: true
- name: Push changes
run: git push

View file

@ -10,7 +10,7 @@ for %%a in (%*) do (
if %FULL_MODE%==1 (
.\tools\xgettext.exe --keyword=L --keyword=_L --keyword=_u8L --keyword=L_CONTEXT:1,2c --keyword=_L_PLURAL:1,2 --add-comments=TRN --from-code=UTF-8 --no-location --debug --boost -f ./localization/i18n/list.txt -o ./localization/i18n/OrcaSlicer.pot
build\\src\\hints\\Release\\hintsToPot ./resources ./localization/i18n
python3 scripts/HintsToPot.py ./resources ./localization/i18n
)
REM Print the current directory
echo %cd%

View file

@ -15,7 +15,7 @@ done
if $FULL_MODE; then
xgettext --keyword=L --keyword=_L --keyword=_u8L --keyword=L_CONTEXT:1,2c --keyword=_L_PLURAL:1,2 --add-comments=TRN --from-code=UTF-8 --no-location --debug --boost -f ./localization/i18n/list.txt -o ./localization/i18n/OrcaSlicer.pot
./build_arm64/src/hints/Release/hintsToPot.app/Contents/MacOS/hintsToPot ./resources ./localization/i18n
python3 scripts/HintsToPot.py ./resources ./localization/i18n
fi

37
scripts/HintsToPot.py Normal file
View file

@ -0,0 +1,37 @@
# Helps converting hints.ini into POT
import sys
from configparser import ConfigParser
from pathlib import Path
def write_to_pot(path: Path, data: dict[str, str]):
with open(path, "a+t") as pot_file:
for key in data.keys():
print(
f"\n#: resources/data/hints.ini: [{ key }]\nmsgid \"{ data[key]['text'] }\"\nmsgstr \"\"",
file=pot_file,
)
def main():
if len(sys.argv) != 3:
print("HINTS_TO_POT FAILED: WRONG NUM OF ARGS")
exit(-1)
path_to_ini = Path(sys.argv[1]).parent / "resources" / "data" / "hints.ini"
path_to_pot = Path(sys.argv[2]).parent / "i18n" / "OrcaSlicer.pot"
if not path_to_ini.exists():
print("HINTS_TO_POT FAILED: PATH TO INI DOES NOT EXISTS")
print(str(path_to_ini))
exit(-1)
config = ConfigParser()
with open(path_to_ini) as hints_file:
config.read_file(hints_file)
write_to_pot(path_to_pot, config._sections)
print("HINTS_TO_POT SUCCESS")
exit(0)
if __name__ == "__main__":
main()