From d9fcc9f720f3a86a69dffeff42b6df81d6495e5a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 5 Feb 2020 14:31:29 +0100 Subject: [PATCH] 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? --- webapp/check-json.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 webapp/check-json.sh diff --git a/webapp/check-json.sh b/webapp/check-json.sh new file mode 100755 index 000000000..2f39bbccb --- /dev/null +++ b/webapp/check-json.sh @@ -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