-
-
Notifications
You must be signed in to change notification settings - Fork 743
Add translation CI validation #4519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0eaf40
Fix broken localization: tr(f-string) never matches translation catalog
Softer 1f4ebd9
Add CI validation for translations and pot_tools dev utility
Softer 5a95a12
Fix code style: use tabs and reformat xgettext arguments
Softer 27ab59e
Replace custom PO parser with msgcmp, drop pot_tools.py
Softer 2f91248
Move translation checks into locales_generator.sh, simplify CI workflow
Softer 9387070
Fix broken .po files: duplicate msgid in Hindi, missing format args i…
Softer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Translation validation | ||
| on: | ||
| push: | ||
| paths: | ||
| - 'archinstall/**/*.py' | ||
| - 'archinstall/locales/**' | ||
| - '.github/workflows/translation-check.yaml' | ||
| pull_request: | ||
| paths: | ||
| - 'archinstall/**/*.py' | ||
| - 'archinstall/locales/**' | ||
| - '.github/workflows/translation-check.yaml' | ||
| jobs: | ||
| translations: | ||
| name: Validate translations | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | ||
| - name: Install gettext | ||
| run: sudo apt-get update && sudo apt-get install -y gettext | ||
| - name: Run translation checks | ||
| run: bash archinstall/locales/locales_generator.sh check | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,109 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| cd $(dirname "$0")/.. | ||
| cd "$(dirname "$0")/.." | ||
|
|
||
| function update_lang() { | ||
| file=${1} | ||
| usage() { | ||
| echo "Usage: ${0} <command>" | ||
| echo "" | ||
| echo "Commands:" | ||
| echo " all Regenerate base.pot and update all languages" | ||
| echo " <lang> Regenerate base.pot and update a single language" | ||
| echo " check Run translation validation checks" | ||
| echo " -h, --help Show this help" | ||
| } | ||
|
|
||
| generate_pot() { | ||
| find . -type f -iname '*.py' | sort \ | ||
| | xargs xgettext --no-location --omit-header --keyword='tr' \ | ||
| -d base -o locales/base.pot | ||
| } | ||
|
|
||
| update_lang() { | ||
| local file=${1} | ||
| echo "Updating: ${file}" | ||
| local path | ||
| path=$(dirname "${file}") | ||
| msgmerge --quiet --no-location --width 512 --backup none --update "${file}" locales/base.pot | ||
| msgfmt -o "${path}/base.mo" "${file}" | ||
| } | ||
|
|
||
|
|
||
| function generate_all() { | ||
| cmd_generate_all() { | ||
| generate_pot | ||
| for file in $(find locales/ -name "base.po"); do | ||
| update_lang "${file}" | ||
| done | ||
| } | ||
|
|
||
| function generate_single_lang() { | ||
| lang_file="locales/${1}/LC_MESSAGES/base.po" | ||
|
|
||
| cmd_generate_single() { | ||
| local lang_file="locales/${1}/LC_MESSAGES/base.po" | ||
| if [ ! -f "${lang_file}" ]; then | ||
| echo "Language files not found: ${lang_file}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| generate_pot | ||
| update_lang "${lang_file}" | ||
| } | ||
|
|
||
| cmd_check_po_syntax() { | ||
| echo "Checking .po syntax..." | ||
| local failed=0 | ||
| while IFS= read -r po; do | ||
| if ! msgfmt --check --output-file=/dev/null "$po" 2>&1; then | ||
| echo "FAIL: $po" | ||
| failed=1 | ||
| fi | ||
| done < <(find locales/ -name '*.po') | ||
| if [ "$failed" -eq 1 ]; then | ||
| echo "ERROR: some .po files have syntax errors" >&2 | ||
| return 1 | ||
| fi | ||
| echo "All .po files passed syntax check." | ||
| } | ||
|
|
||
| cmd_check_no_tr_fstring() { | ||
| echo "Checking for tr(f-string) anti-pattern..." | ||
| if grep -rnE "tr\(\s*f['\"]" . --include='*.py'; then | ||
| echo "ERROR: use tr('...{}').format(...) instead of tr(f'...')" >&2 | ||
| return 1 | ||
| fi | ||
| echo "No tr(f-string) anti-pattern found." | ||
| } | ||
|
|
||
| cmd_check_pot_freshness() { | ||
| # msgcmp (not diff) because base.pot carries legacy stale entries from | ||
| # --join-existing; diff would always fail until a full cleanup is done. | ||
| echo "Checking base.pot for missing strings..." | ||
| find . -type f -iname '*.py' | sort \ | ||
| | xargs xgettext --no-location --omit-header --keyword='tr' \ | ||
| -d base -o /tmp/generated.pot | ||
| if ! msgcmp --use-untranslated locales/base.pot /tmp/generated.pot; then | ||
| echo "ERROR: base.pot is missing strings - run: locales_generator.sh all" >&2 | ||
| return 1 | ||
| fi | ||
| echo "base.pot contains all translatable strings." | ||
| } | ||
|
|
||
| cmd_check() { | ||
| local failed=0 | ||
| cmd_check_po_syntax || failed=1 | ||
| cmd_check_no_tr_fstring || failed=1 | ||
| cmd_check_pot_freshness || failed=1 | ||
| if [ "$failed" -eq 1 ]; then | ||
| echo "Some translation checks failed." >&2 | ||
| exit 1 | ||
| fi | ||
| echo "All translation checks passed." | ||
| } | ||
|
|
||
| if [ $# -eq 0 ]; then | ||
| echo "Usage: ${0} <language_abbr>" | ||
| echo "Special case 'all' for <language_abbr> builds all languages." | ||
| usage | ||
| exit 1 | ||
| fi | ||
|
|
||
| lang=${1} | ||
|
|
||
| # Update the base file containing all translatable strings | ||
| find . -type f -iname "*.py" | xargs xgettext --join-existing --no-location --omit-header --keyword='tr' -d base -o locales/base.pot | ||
|
|
||
| case "${lang}" in | ||
| "all") generate_all;; | ||
| *) generate_single_lang "${lang}" | ||
| case "${1}" in | ||
| check) cmd_check ;; | ||
| all) cmd_generate_all ;; | ||
| -h|--help) usage ;; | ||
| *) cmd_generate_single "${1}" ;; | ||
| esac |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify this even more, for example
All these checks are only in the GH action which makes them difficult to test, so I suggest to put these into the already existing
locale_generator.shfile and call them from here. That means during dev they can actually be called and tested and there is a single source of truth.At that point this whole action can be reduced to
and the checks implemented in the bash file instead. As an example you can then have this in the script