Last active
November 6, 2025 23:34
-
-
Save fgregg/dfff74734d4bdcb2b46a0fb2a7126502 to your computer and use it in GitHub Desktop.
Script to check that you have not introduced untranslated strings.
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
| #!/bin/bash | |
| # Check that all translations are complete | |
| # Save original .po file for comparison | |
| cp locale/es/LC_MESSAGES/django.po locale/es/LC_MESSAGES/django.po.bak | |
| # Run makemessages to update .po file | |
| python manage.py makemessages -l es > /dev/null 2>&1 | |
| # Get translation statistics | |
| STATS=$(msgfmt --statistics locale/es/LC_MESSAGES/django.po 2>&1) | |
| # Check if there are any untranslated or fuzzy strings | |
| if echo "$STATS" | grep -qE "fuzzy|untranslated"; then | |
| echo "β Translation check failed!" | |
| echo "$STATS" | |
| echo "" | |
| # Show untranslated strings with file locations and content | |
| echo "Untranslated strings:" | |
| msgattrib --untranslated locale/es/LC_MESSAGES/django.po | \ | |
| awk '/^#: / {location=$0; next} /^msgid / && location && $0 !~ /^msgid ""$/ {gsub(/^msgid /, "", $0); gsub(/"$/, "", $0); gsub(/^"/, "", $0); print " π " substr(location, 4) ": " $0; location=""}' | |
| echo "" | |
| # Show fuzzy strings with file locations and content | |
| echo "Fuzzy strings (need review):" | |
| msgattrib --only-fuzzy locale/es/LC_MESSAGES/django.po | \ | |
| awk '/^#: / {location=$0; next} /^msgid / && location && $0 !~ /^msgid ""$/ {gsub(/^msgid /, "", $0); gsub(/"$/, "", $0); gsub(/^"/, "", $0); print " π " substr(location, 4) ": " $0; location=""}' | |
| echo "" | |
| echo "Please translate all strings in locale/es/LC_MESSAGES/django.po" | |
| # Clean up backup file | |
| rm -f locale/es/LC_MESSAGES/django.po.bak | |
| exit 1 | |
| fi | |
| echo "β All translations are complete" | |
| # Check if there are substantive changes (ignoring timestamps and line number references) | |
| # We'll compare the files while filtering out: | |
| # - POT-Creation-Date lines (timestamps) | |
| # - #: lines (source code location references with line numbers) | |
| DIFF=$(diff \ | |
| <(grep -v "^\"POT-Creation-Date:" locale/es/LC_MESSAGES/django.po.bak | grep -v "^#:") \ | |
| <(grep -v "^\"POT-Creation-Date:" locale/es/LC_MESSAGES/django.po | grep -v "^#:")) | |
| # If there are no substantive differences, restore the original file | |
| if [ -z "$DIFF" ]; then | |
| mv locale/es/LC_MESSAGES/django.po.bak locale/es/LC_MESSAGES/django.po | |
| else | |
| # There are substantive changes, keep the new file and remove backup | |
| rm locale/es/LC_MESSAGES/django.po.bak | |
| fi | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment