mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Rearrange script for readability and add exit 1
exit 1 if differences are found to notify pipeline!
This commit is contained in:
parent
24d712e30e
commit
d4a576cdd3
@ -1,14 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Ensure locale is set to C for predictable sorting
|
||||
export LC_ALL=C
|
||||
export LC_COLLATE=C
|
||||
|
||||
# Get the script's own path
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# Directory containing the JSON files to sort
|
||||
DIR="$1"
|
||||
found_missing_keys=false
|
||||
|
||||
|
||||
##### Log Setup #####
|
||||
# Log file path
|
||||
LOGFILE="${SCRIPT_DIR}/lang_sort_log.txt"
|
||||
|
||||
# Redirect stdout and stderr to the logfile
|
||||
exec > "${LOGFILE}" 2>&1
|
||||
#####################
|
||||
|
||||
|
||||
##### Exit Gates #####
|
||||
# Check if jq is installed
|
||||
if ! command -v jq &> /dev/null
|
||||
then
|
||||
@ -22,18 +34,13 @@ if [ "$#" -ne 1 ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Directory containing the JSON files to sort
|
||||
DIR="$1"
|
||||
|
||||
# Check if en_EN.json exists in the directory
|
||||
if [[ ! -f "${DIR}/en_EN.json" ]]; then
|
||||
echo "The file en_EN.json does not exist in ${DIR}.Ensure you have the right directory, Exiting."
|
||||
exit
|
||||
fi
|
||||
######################
|
||||
|
||||
# Ensure locale is set to C for predictable sorting
|
||||
export LC_ALL=C
|
||||
export LC_COLLATE=C
|
||||
|
||||
# Sort keys of the en_EN.json file with 4-space indentation and overwrite it
|
||||
jq -S --indent 4 '.' "${DIR}/en_EN.json" > "${DIR}/en_EN.json.tmp" && mv "${DIR}/en_EN.json.tmp" "${DIR}/en_EN.json"
|
||||
@ -59,6 +66,7 @@ for file in "${DIR}"/*.json; do
|
||||
# Display keys present in en_EN.json but not in the current file
|
||||
missing_keys=$(comm -23 "${ref_keys}" "${current_keys}")
|
||||
if [[ -n "${missing_keys}" ]]; then
|
||||
found_missing_keys=true
|
||||
echo -e "\nKeys/subkeys present in en_EN.json but missing in $(basename "${file}"): "
|
||||
echo "${missing_keys}"
|
||||
fi
|
||||
@ -74,4 +82,14 @@ done
|
||||
# Remove the temporary file
|
||||
rm -f "${ref_keys}"
|
||||
|
||||
echo -e "\n\nComparison and sorting complete!"
|
||||
if ${found_missing_keys}; then
|
||||
echo -e "\n\nSorting complete!"
|
||||
echo "Comparison found missing keys, Please Review!"
|
||||
echo "-------------------------------------------------------------------"
|
||||
echo "If there are stale translations, you can exclude with '_incomplete'"
|
||||
echo " e.g. lol_EN_incomplete.json"
|
||||
echo "-------------------------------------------------------------------"
|
||||
exit 1
|
||||
else
|
||||
echo -e "\n\nComparison and Sorting complete!"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user