forked from KZGlobalTeam/cs2kz-metamod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upload translations quotes check script
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |