mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-08-09 17:26:20 +00:00
Two related changes to the translation infrastructure: 1. Add Swedish (sv) as a supported locale in both the CLI and Monitor translation systems. Inspired by PR #121, which arrived before the current auto-generated cache layout existed. 2. Include Slovak (sk) in the default auto-fill target set. Guardrail #1 in build_i18n_messages.py never overwrites a key whose target value differs from EN, so Vaso73's curated Slovak strings stay intact — auto-translation only fills keys that are still on the English fallback. Trade-off accepted: sk users see decent machine translation for new keys immediately instead of raw English while human curation catches up, and Vaso73 keeps full ownership of the wording via follow-up PRs. Changes: - AppImage/lib/i18n/languages.ts: add "sv" to LanguageCode + register in SUPPORTED_LANGUAGES. - AppImage/messages/sv/common.json: stub — will be filled by the i18n workflow on the local bootstrap. - .github/scripts/build_translation_cache.py: add "sv" to DEFAULT_LANGUAGES. - .github/scripts/build_i18n_messages.py: add "sk" and "sv" to DEFAULT_LANGUAGES; update comments to explain the sk decision. - .github/workflows/build-i18n-messages.yml: default input includes sk + sv; comments updated to match.
108 lines
3.9 KiB
YAML
108 lines
3.9 KiB
YAML
name: Build i18n messages
|
||
|
||
# Auto-translate missing keys in AppImage/messages/<locale>/common.json
|
||
# against the English source whenever the source changes.
|
||
#
|
||
# The Monitor's i18n layer (AppImage/lib/i18n/provider.tsx) does its own
|
||
# runtime fallback (locale → en → key), so this workflow doesn't break
|
||
# anything if it misses a key: it just eliminates the visible-English
|
||
# blocks in non-en locales.
|
||
#
|
||
# Guardrails baked into build_i18n_messages.py:
|
||
# - Never overwrites a key whose target value differs from EN (i.e.
|
||
# already translated by a human). This is what makes it safe to
|
||
# include sk in the default set: Vaso73's curated strings are
|
||
# protected end-to-end; auto only fills keys still on the EN
|
||
# fallback.
|
||
# - `{placeholder}` tokens are protected end-to-end.
|
||
#
|
||
# Triggers:
|
||
# - push to develop touching AppImage/messages/en/common.json
|
||
# - manual via workflow_dispatch
|
||
|
||
on:
|
||
push:
|
||
branches: [develop]
|
||
paths:
|
||
- 'AppImage/messages/en/common.json'
|
||
- '.github/scripts/build_i18n_messages.py'
|
||
- '.github/workflows/build-i18n-messages.yml'
|
||
workflow_dispatch:
|
||
inputs:
|
||
refresh:
|
||
description: 'Re-translate every key (overwrites human translations!)'
|
||
type: boolean
|
||
default: false
|
||
languages:
|
||
description: 'Comma-separated locales. Default: es,de,fr,it,pt,sk,sv (guardrail protects Vaso73 sk).'
|
||
default: 'es,de,fr,it,pt,sk,sv'
|
||
|
||
# Prevent two runs from racing on the same branch and fighting over the
|
||
# auto-commit. cancel-in-progress:false because a full first-run may take
|
||
# ~30 min for the initial bootstrap and interrupting mid-flight would
|
||
# waste the calls already made.
|
||
concurrency:
|
||
group: build-i18n-messages-${{ github.ref }}
|
||
cancel-in-progress: false
|
||
|
||
jobs:
|
||
translate:
|
||
runs-on: ubuntu-latest
|
||
permissions:
|
||
contents: write # auto-commit AppImage/messages/*/common.json to develop
|
||
# First-run bootstrap of ~5 locales × 3.8k keys can take a while at
|
||
# 0.15s/call with rate-limit backoffs. 90 min headroom.
|
||
timeout-minutes: 90
|
||
|
||
steps:
|
||
- name: Checkout develop
|
||
uses: actions/checkout@v4
|
||
with:
|
||
ref: develop
|
||
# Full history so the auto-commit doesn't drift when another
|
||
# push landed between trigger and this job start.
|
||
fetch-depth: 0
|
||
token: ${{ secrets.GITHUB_TOKEN }}
|
||
|
||
- name: Set up Python
|
||
uses: actions/setup-python@v5
|
||
with:
|
||
python-version: '3.11'
|
||
|
||
- name: Install googletrans
|
||
run: |
|
||
python -m pip install --upgrade pip
|
||
# Same pinning as build-translation-cache.yml so the two
|
||
# workflows share behavior. Bump both in lockstep.
|
||
pip install 'googletrans==4.0.0-rc1' 'httpx==0.13.3' 'httpcore==0.9.1' 'h11==0.9.0'
|
||
|
||
- name: Translate missing keys
|
||
run: |
|
||
REFRESH_FLAG=""
|
||
if [[ "${{ github.event.inputs.refresh }}" == "true" ]]; then
|
||
REFRESH_FLAG="--refresh"
|
||
fi
|
||
LANGS="${{ github.event.inputs.languages }}"
|
||
LANGS="${LANGS:-es,de,fr,it,pt}"
|
||
python .github/scripts/build_i18n_messages.py \
|
||
--source AppImage/messages/en/common.json \
|
||
--messages-dir AppImage/messages \
|
||
--languages "$LANGS" \
|
||
--provider googletrans \
|
||
$REFRESH_FLAG
|
||
|
||
- name: Commit + push if changed
|
||
run: |
|
||
if git diff --quiet -- AppImage/messages/; then
|
||
echo "No translation changes — skipping commit."
|
||
exit 0
|
||
fi
|
||
git config user.name "ProxMenuxBot"
|
||
git config user.email "bot@proxmenux.local"
|
||
git add AppImage/messages/
|
||
git commit -m "chore(i18n): auto-fill missing translations in messages/{locale}/common.json
|
||
|
||
Source: ${GITHUB_SHA::7}
|
||
Triggered by: ${{ github.event_name }}"
|
||
git push origin develop
|