Basic script to normalize the locale files and check if those files are normalized

To Do: Check if keys in en.json and de.json are the same
Check dependencies (jq must be installed)
Where to place the file?
Add test to travis? How?
This commit is contained in:
Moriz Wahl 2020-02-05 14:31:29 +01:00
parent e35ca59fbc
commit d9fcc9f720

44
webapp/check-json.sh Executable file
View File

@ -0,0 +1,44 @@
#! /usr/bin/env bash
ERRORS=false
FIX=false
for arg in "$@"
do
if [ "$arg" == "--fix" ]
then
FIX=true
fi
done
# normalize the locale file. WS 2 blanks, keys are sorted
if $FIX ; then
for locale_file in locales/*.json
do
jq --sort-keys . $locale_file > locales/tmp.json
mv locales/tmp.json $locale_file
done
exit 0
fi
# check if keys are sorted alphabetically and WS is two blanks
for locale_file in locales/*.json
do
jq --sort-keys . $locale_file | diff -q $locale_file - > /dev/null && echo "$locale_file is OK" ||
{ ERRORS=true ; echo "$locale_file is not normalized" ; }
done
# check if all the keys in en.json are present in de.json and vice versa
# TO DO!!
# Exit with status 1 if there were errors
if $ERRORS ; then
echo "Some locale files are not normalized."
exit 1
else
echo "All locales are normalized."
exit 0
fi