Test translation imports

Test imported files whether those are valid (can be compiled by
gettext) and do not propose them if they are invalid.

If there are invalid files, a proposal of valid files will still happen.
The script will fail at the end so that these invalid files can be
detected.

Change-Id: Ia48181bc79903dd47be054a6f7c7ee535506d282
This commit is contained in:
Andreas Jaeger 2016-01-30 17:03:15 +01:00
parent b7612d58a0
commit aa3d342839
2 changed files with 29 additions and 1 deletions

View File

@ -22,6 +22,9 @@ TOPIC=zanata/translations
# Used for setup.py babel commands
QUIET="--quiet"
# Have invalid files been found?
INVALID_PO_FILE=0
# Get a module name of a project
function get_modulename {
local project=$1
@ -381,8 +384,12 @@ function setup_django_openstack_auth {
'{locale_with_underscore}/LC_MESSAGES/django.po' -f zanata.xml
}
# Filter out files that we do not want to commit
# Filter out files that we do not want to commit.
# Sets global variable INVALID_PO_FILE to 1 if any invalid files are
# found.
function filter_commits {
local ret
# Don't add new empty files.
for f in $(git diff --cached --name-only --diff-filter=A); do
# Files should have at least one non-empty msgid string.
@ -409,6 +416,21 @@ function filter_commits {
| egrep -v "$REGEX" \
| egrep -c "^([+][^+#])")
set -e
# Check that imported po files are valid
if [[ $f =~ .po$ ]] ; then
set +e
msgfmt --check-format -o /dev/null $f
ret=$?
set -e
if [ $ret -ne "0" ] ; then
# Set change to zero so that next expression reverts
# change of this file.
changed=0
echo "ERROR: File $f is an invalid po file."
echo "ERROR: The file has not been imported and needs fixing!"
INVALID_PO_FILE=1
fi
fi
if [ $changed -eq 0 ]; then
git reset -q "$f"
git checkout -- "$f"

View File

@ -258,3 +258,9 @@ filter_commits
# Propose patch to gerrit if there are changes.
send_patch "$BRANCH"
if [ $INVALID_PO_FILE -eq 1 ] ; then
echo "At least one po file in invalid. Fix all invalid files on the"
echo "translation server."
exit 1
fi