mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-19 01:35:28 +01: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
|
#!/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
|
# Get the script's own path
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
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
|
# Log file path
|
||||||
LOGFILE="${SCRIPT_DIR}/lang_sort_log.txt"
|
LOGFILE="${SCRIPT_DIR}/lang_sort_log.txt"
|
||||||
|
|
||||||
# Redirect stdout and stderr to the logfile
|
# Redirect stdout and stderr to the logfile
|
||||||
exec > "${LOGFILE}" 2>&1
|
exec > "${LOGFILE}" 2>&1
|
||||||
|
#####################
|
||||||
|
|
||||||
|
|
||||||
|
##### Exit Gates #####
|
||||||
# Check if jq is installed
|
# Check if jq is installed
|
||||||
if ! command -v jq &> /dev/null
|
if ! command -v jq &> /dev/null
|
||||||
then
|
then
|
||||||
@ -22,18 +34,13 @@ if [ "$#" -ne 1 ]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Directory containing the JSON files to sort
|
|
||||||
DIR="$1"
|
|
||||||
|
|
||||||
# Check if en_EN.json exists in the directory
|
# Check if en_EN.json exists in the directory
|
||||||
if [[ ! -f "${DIR}/en_EN.json" ]]; then
|
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."
|
echo "The file en_EN.json does not exist in ${DIR}.Ensure you have the right directory, Exiting."
|
||||||
exit
|
exit
|
||||||
fi
|
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
|
# 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"
|
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
|
# Display keys present in en_EN.json but not in the current file
|
||||||
missing_keys=$(comm -23 "${ref_keys}" "${current_keys}")
|
missing_keys=$(comm -23 "${ref_keys}" "${current_keys}")
|
||||||
if [[ -n "${missing_keys}" ]]; then
|
if [[ -n "${missing_keys}" ]]; then
|
||||||
|
found_missing_keys=true
|
||||||
echo -e "\nKeys/subkeys present in en_EN.json but missing in $(basename "${file}"): "
|
echo -e "\nKeys/subkeys present in en_EN.json but missing in $(basename "${file}"): "
|
||||||
echo "${missing_keys}"
|
echo "${missing_keys}"
|
||||||
fi
|
fi
|
||||||
@ -74,4 +82,14 @@ done
|
|||||||
# Remove the temporary file
|
# Remove the temporary file
|
||||||
rm -f "${ref_keys}"
|
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…
x
Reference in New Issue
Block a user