117 lines
2.9 KiB
Bash
Executable File
117 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$repo_root"
|
|
|
|
threshold="${THRESHOLD_PERCENT:-30}"
|
|
output_file="${1:-}"
|
|
|
|
if [[ -n "$output_file" ]]; then
|
|
exec >"$output_file"
|
|
fi
|
|
|
|
if [[ ! -d docs/en || ! -d docs/cs ]]; then
|
|
echo "ERROR: expected docs/en and docs/cs directories."
|
|
exit 1
|
|
fi
|
|
|
|
tmp_dir="$(mktemp -d)"
|
|
trap 'rm -rf "$tmp_dir"' EXIT
|
|
|
|
(cd docs/en && rg --files -g '*.md' | sort) >"$tmp_dir/en_files.txt"
|
|
(cd docs/cs && rg --files -g '*.md' | sort) >"$tmp_dir/cs_files.txt"
|
|
|
|
comm -23 "$tmp_dir/en_files.txt" "$tmp_dir/cs_files.txt" >"$tmp_dir/missing_in_cs.txt"
|
|
comm -13 "$tmp_dir/en_files.txt" "$tmp_dir/cs_files.txt" >"$tmp_dir/extra_in_cs.txt"
|
|
comm -12 "$tmp_dir/en_files.txt" "$tmp_dir/cs_files.txt" >"$tmp_dir/common_files.txt"
|
|
|
|
missing_count="$(wc -l <"$tmp_dir/missing_in_cs.txt" | tr -d ' ')"
|
|
extra_count="$(wc -l <"$tmp_dir/extra_in_cs.txt" | tr -d ' ')"
|
|
|
|
# Report any TODO markers in Czech files.
|
|
todo_count="$(
|
|
(rg -n '\bTODO\b' docs/cs --glob '*.md' --glob '!README.md' || true) | wc -l | tr -d ' '
|
|
)"
|
|
|
|
echo "# Translation Parity Report (docs/en -> docs/cs)"
|
|
echo
|
|
echo "## Summary"
|
|
echo
|
|
echo "- English files: $(wc -l <"$tmp_dir/en_files.txt" | tr -d ' ')"
|
|
echo "- Czech files: $(wc -l <"$tmp_dir/cs_files.txt" | tr -d ' ')"
|
|
echo "- Missing in Czech: $missing_count"
|
|
echo "- Extra in Czech: $extra_count"
|
|
echo "- Czech TODO markers (excluding docs/cs/README.md): $todo_count"
|
|
echo
|
|
|
|
if [[ "$missing_count" -gt 0 ]]; then
|
|
echo "## Missing Czech Files"
|
|
echo
|
|
while IFS= read -r rel; do
|
|
echo "- docs/cs/$rel"
|
|
done <"$tmp_dir/missing_in_cs.txt"
|
|
echo
|
|
fi
|
|
|
|
if [[ "$extra_count" -gt 0 ]]; then
|
|
echo "## Extra Czech Files"
|
|
echo
|
|
while IFS= read -r rel; do
|
|
echo "- docs/cs/$rel"
|
|
done <"$tmp_dir/extra_in_cs.txt"
|
|
echo
|
|
fi
|
|
|
|
echo "## Line Count Delta (warnings at >= ${threshold}%)"
|
|
echo
|
|
echo "| File | EN lines | CS lines | Delta |"
|
|
echo "| --- | ---: | ---: | ---: |"
|
|
|
|
warn_count=0
|
|
while IFS= read -r rel; do
|
|
en_lines="$(wc -l <"docs/en/$rel" | tr -d ' ')"
|
|
cs_lines="$(wc -l <"docs/cs/$rel" | tr -d ' ')"
|
|
|
|
if [[ "$en_lines" -eq 0 ]]; then
|
|
delta_percent="n/a"
|
|
abs_percent=0
|
|
else
|
|
abs_percent="$(
|
|
awk -v en="$en_lines" -v cs="$cs_lines" 'BEGIN{
|
|
d = cs - en; if (d < 0) d = -d;
|
|
printf "%.1f", (d / en) * 100
|
|
}'
|
|
)"
|
|
delta_percent="${abs_percent}%"
|
|
fi
|
|
|
|
echo "| \`$rel\` | $en_lines | $cs_lines | $delta_percent |"
|
|
|
|
if [[ "$en_lines" -gt 0 ]]; then
|
|
over="$(
|
|
awk -v p="$abs_percent" -v t="$threshold" 'BEGIN{if (p >= t) print 1; else print 0}'
|
|
)"
|
|
if [[ "$over" -eq 1 ]]; then
|
|
warn_count=$((warn_count + 1))
|
|
fi
|
|
fi
|
|
done <"$tmp_dir/common_files.txt"
|
|
|
|
echo
|
|
echo "Large-delta warnings: $warn_count"
|
|
|
|
status=0
|
|
if [[ "$missing_count" -gt 0 || "$todo_count" -gt 0 ]]; then
|
|
status=1
|
|
fi
|
|
|
|
echo
|
|
if [[ "$status" -eq 0 ]]; then
|
|
echo "Result: PASS"
|
|
else
|
|
echo "Result: FAIL (missing files and/or TODO markers found)"
|
|
fi
|
|
|
|
exit "$status"
|