Ocelot-Social/webapp/check-json.sh
Moriz Wahl d9fcc9f720 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?
2020-02-18 18:05:28 +01:00

45 lines
897 B
Bash
Executable File

#! /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