Skip to content

Commit

Permalink
upload translations quotes check script
Browse files Browse the repository at this point in the history
  • Loading branch information
jvnipers committed Feb 5, 2025
1 parent f0b6a2f commit 94944bf
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions scripts/check-translations-quotes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

check_file() {
local file="$1"
local line_number=0
local errors_found=0

while IFS= read -r line; do
((line_number++))

[[ -z "$line" || "$line" =~ ^[[:space:]]*([{}]|//) ]] && continue

local line_without_comment=$(echo "$line" | sed -E 's/([^:])\/\/.*$/\1/')

local cleaned_line=$(echo "$line_without_comment" | sed 's/\\"/X/g')

local quote_count=$(echo "$cleaned_line" | tr -cd '"' | wc -c)

if [[ $quote_count -eq 2 ]]; then
if [[ ! "$cleaned_line" =~ ^[[:space:]]*\"[^\"]+\"[[:space:]]*$ ]]; then
echo "Error in $file:$line_number - Incorrect single-quote format: $line"
((errors_found++))
fi
elif [[ $quote_count -eq 4 ]]; then
if [[ ! "$cleaned_line" =~ ^[[:space:]]*\"[^\"]+\"[[:space:]]*\"[^\"]*\"[[:space:]]*$ ]]; then
echo "Error in $file:$line_number - Incorrect key-value format: $line"
((errors_found++))
fi
else
if [[ $quote_count -ne 0 ]]; then
echo "Error in $file:$line_number - Incorrect number of quotes (expected 2 or 4, found $quote_count): $line"
((errors_found++))
fi
fi
done < "$file"

return $errors_found
}

errors_total=0
exit_code=0

while IFS= read -r -d '' file; do
check_file "$file"
errors_total=$((errors_total + $?))
done < <(find ./translations -type f -name "*.txt" -print0)

if [ $errors_total -eq 0 ]; then
echo "No errors found. All strings are properly formatted."
else
echo "Total errors found: $errors_total"
exit_code=1
fi

exit "$exit_code"

0 comments on commit 94944bf

Please sign in to comment.