Browse Source

fix some logic flaws, and improve comments and style

pull/918/head
Max Mehl 5 months ago
parent
commit
4e64bdfa22
Signed by: max.mehl <max.mehl@fsfe.org> GPG Key ID: 2704E4AB371E2E92
1 changed files with 96 additions and 16 deletions
  1. 96
    16
      tools/check-translation-status.sh

+ 96
- 16
tools/check-translation-status.sh View File

@@ -1,25 +1,105 @@
#!/bin/bash

A=$(echo $1 | sed 's/\.[a-z][a-z]\.xhtml//')
originaldate=`git log --pretty="%cd" --date=raw -1 $A.en.xhtml|cut -d' ' -f1`
print_usage() {
echo "Check the translation status of a file"
echo ""
echo "Usage: ./check-translation-status.sh [-a] [-q] -f file.en.xml"
echo ""
echo " -f FILENAME"
echo " (Relative or absolute path to file that shall be checked)"
echo ""
echo " -a (If given, checks all available translations of the file)"
echo ""
echo " -q (If given, do not write anything to STDOUT)"
echo ""
echo " -h (HELP)"
echo ""
echo "Exit codes:"
echo " 0 = file is up-to-date"
echo " 1 = file is outdated"
echo " 2 = file is not supported"
}

EN=$A.en.xhtml
trdate=`git log --pretty="%cd" --date=raw -1 $EN|cut -d' ' -f1`
ymd=`date +"%Y-%m-%d" --date="@$trdate"`
echo "Basefile: $EN ( $ymd )"
echo " STATUS LANG DATE"
echo " -------- ---- ----------"
ALL="0"
QUIET="0"
while getopts f:aq OPT; do
case $OPT in
f) FILE=$OPTARG;;
a) ALL="1";;
q) QUIET="1";;
h) print_help;;
esac
done

for i in $A.[a-z][a-z].xhtml; do
# show usage if no parameter given
if [ "$1" = "" ]; then
print_usage
exit 0
fi

function out {
if [ "$QUIET" != "1" ]; then
echo "$@"
fi
}

# Get file extension
EXT="${FILE##*.}"
if ! [[ "$EXT" =~ ^(xhtml|xml)$ ]]; then
out "Only works for files ending with .xhtml or .xml"
exit 2
fi

# remove "en.$EXT"
A=$(echo "$FILE" | sed -E "s/\.[a-z][a-z]\.$EXT//")
# get change date of English file
EN=$A.en.$EXT
endate=$(git log --pretty="%cd" --date=raw -1 "$EN"|cut -d' ' -f1)
# Convert to YYYY-MM-DD
ymd=$(date +"%Y-%m-%d" --date="@$endate")
out "Basefile: $EN ( $ymd )"
out " STATUS LANG DATE"
out " -------- ---- ----------"

if [ "$ALL" == "1" ]; then
# Loop over all translations of this file
for i in "$A".[a-z][a-z].$EXT; do
if [[ $i != *".en."* ]]; then
# get language code
lang=$(echo "$i"|sed "s/.*\.\([a-z][a-z]\)\.$EXT/\1/")
# get change date of translation
trdate=$(git log --pretty="%cd" --date=raw -1 "$i"|cut -d' ' -f1)
# Convert to YYYY-MM-DD
ymd=$(date +"%Y-%m-%d" --date="@$trdate")
# get time difference in seconds
diff=$((trdate-endate))
# mark as outdated if difference larger than 1 hour
if [[ $diff -lt -3600 ]]; then
out " OUTDATED $lang $ymd"
else
out " Up-to-date $lang $ymd"
fi
fi
done | sort
exit 0
else
i="$FILE"
if [[ $i != *".en."* ]]; then
trdate=`git log --pretty="%cd" --date=raw -1 $i|cut -d' ' -f1`
ymd=`date +"%Y-%m-%d" --date="@$trdate"`
diff=$((trdate-originaldate))
lang=`echo $i|sed 's/.*\.\([a-z][a-z]\)\.xhtml/\1/'`
# get language code
lang=$(echo "$i"|sed "s/.*\.\([a-z][a-z]\)\.$EXT/\1/")
# get change date of translation
trdate=$(git log --pretty="%cd" --date=raw -1 "$i"|cut -d' ' -f1)
# Convert to YYYY-MM-DD
ymd=$(date +"%Y-%m-%d" --date="@$trdate")
# get time difference in seconds
diff=$((trdate-endate))
# mark as outdated if difference larger than 1 hour
if [[ $diff -lt -3600 ]]; then
echo " OUTDATED $lang $ymd"
out " OUTDATED $lang $ymd"
exit 1
else
echo " Up-to-date $lang $ymd"
out " Up-to-date $lang $ymd"
exit 0
fi
fi
done | sort
fi

Loading…
Cancel
Save