add -o parameter and improve some logic and comments
the build was successful Details

This commit is contained in:
Max Mehl 2019-05-23 14:45:17 +02:00
parent 5600c547b0
commit b3fd5ba6a6
Signed by: max.mehl
GPG Key ID: 2704E4AB371E2E92
1 changed files with 27 additions and 7 deletions

View File

@ -5,9 +5,12 @@ print_usage() {
echo "" echo ""
echo "Usage: ./check-translation-status.sh [-a] [-q] -f file.en.xml" echo "Usage: ./check-translation-status.sh [-a] [-q] -f file.en.xml"
echo "" echo ""
echo " -f FILENAME" echo " -f <FILENAME>"
echo " (Relative or absolute path to file that shall be checked)" echo " (Relative or absolute path to file that shall be checked)"
echo "" echo ""
echo " -o up|out"
echo " (Only print language code whose translations are up-to-date or outdated)"
echo ""
echo " -a (If given, checks all available translations of the file)" echo " -a (If given, checks all available translations of the file)"
echo "" echo ""
echo " -q (If given, do not write anything to STDOUT)" echo " -q (If given, do not write anything to STDOUT)"
@ -22,21 +25,28 @@ print_usage() {
ALL="0" ALL="0"
QUIET="0" QUIET="0"
while getopts f:aq OPT; do while getopts f:o:aq OPT; do
case $OPT in case $OPT in
f) FILE=$OPTARG;; f) FILE=$OPTARG;; # file name
a) ALL="1";; a) ALL="1";;
q) QUIET="1";; q) QUIET="1";;
o) ONLY=$OPTARG;; # print only languages which are up/outdated
h) print_help;; h) print_help;;
esac esac
done done
# show usage if no parameter given # show usage if no required parameter given
if [ "$1" = "" ]; then if [ "$1" = "" ] || [ -z "$FILE" ]; then
print_usage print_usage
exit 0 exit 0
fi fi
# -o supresses all other output (-q), and implicates -a
if [ ! -z "$ONLY" ]; then
QUIET="1"
ALL="1"
fi
function out { function out {
if [ "$QUIET" != "1" ]; then if [ "$QUIET" != "1" ]; then
echo "$@" echo "$@"
@ -80,9 +90,17 @@ if [ "$ALL" == "1" ]; then
# mark as outdated if difference larger than 1 hour # mark as outdated if difference larger than 1 hour
if [[ $diff -lt -3600 ]]; then if [[ $diff -lt -3600 ]]; then
out " OUTDATED $lang $ymd" out " OUTDATED $lang $ymd"
# print outdated language code
if [ "$ONLY" == "out" ]; then
echo "$lang"
fi
else else
out " Up-to-date $lang $ymd" out " Up-to-date $lang $ymd"
fi # print up-to-date language code
if [ "$ONLY" == "up" ]; then
echo "$lang"
fi
fi
fi fi
done | sort done | sort
exit 0 exit 0
@ -105,5 +123,7 @@ else
out " Up-to-date $lang $ymd" out " Up-to-date $lang $ymd"
exit 0 exit 0
fi fi
fi else
out " (Comparing status of English file does not make sense)"
fi
fi fi