Specialized agent for post-translation quality validation. Validates completeness, format integrity, and translation quality.
- Content completeness: All sections translated
- Format preservation: Markdown syntax intact
- Quality assessment: Chinese language quality check
- File integrity: UTF-8 encoding and proper structure
# Parse validation task: "validate: source=[file] target=[output_file]"
parse_validation_task() {
local task="$1"
SOURCE_FILE=$(echo "$task" | grep -o "source=[^ ]*" | cut -d'=' -f2)
TARGET_FILE=$(echo "$task" | grep -o "target=[^ ]*" | cut -d'=' -f2)
echo "π Validating translation:"
echo "π Source: $SOURCE_FILE"
echo "π Target: $TARGET_FILE"
validate_translation "$SOURCE_FILE" "$TARGET_FILE"
}validate_translation() {
local source_file=$1
local target_file=$2
local validation_report=".amazon_q_logs/validation_$(basename "$target_file").log"
echo "=== VALIDATION REPORT ===" > "$validation_report"
echo "Time: $(date)" >> "$validation_report"
echo "Source: $source_file" >> "$validation_report"
echo "Target: $target_file" >> "$validation_report"
echo "" >> "$validation_report"
local critical_errors=0
local warnings=0
# Check 1: File existence
if [ ! -f "$target_file" ]; then
echo "β CRITICAL: Target file missing" >> "$validation_report"
critical_errors=$((critical_errors + 1))
else
echo "β
Target file exists" >> "$validation_report"
fi
# Check 2: UTF-8 encoding
if ! file "$target_file" | grep -q "UTF-8"; then
echo "β οΈ WARNING: File encoding may not be UTF-8" >> "$validation_report"
warnings=$((warnings + 1))
else
echo "β
UTF-8 encoding confirmed" >> "$validation_report"
fi
# Check 3: Chinese content
if ! grep -q '[δΈ-ιΎ]' "$target_file" 2>/dev/null; then
echo "β CRITICAL: No Chinese characters found" >> "$validation_report"
critical_errors=$((critical_errors + 1))
else
echo "β
Chinese content detected" >> "$validation_report"
fi
# Check 4: File size comparison
local source_lines=$(wc -l < "$source_file" 2>/dev/null || echo 0)
local target_lines=$(wc -l < "$target_file" 2>/dev/null || echo 0)
if [ $source_lines -gt 0 ]; then
local size_ratio=$((target_lines * 100 / source_lines))
if [ $size_ratio -lt 40 ] || [ $size_ratio -gt 200 ]; then
echo "β οΈ WARNING: Size ratio unusual ($size_ratio%)" >> "$validation_report"
warnings=$((warnings + 1))
else
echo "β
File size reasonable ($size_ratio%)" >> "$validation_report"
fi
fi
# Check 5: Markdown structure
validate_markdown_structure "$source_file" "$target_file" "$validation_report"
# Check 6: Translation quality
assess_translation_quality "$target_file" "$validation_report"
# Final validation result
if [ $critical_errors -gt 0 ]; then
echo "β VALIDATION FAILED: $critical_errors critical errors" >> "$validation_report"
echo "β VALIDATION FAILED for $(basename "$target_file")"
return 1
elif [ $warnings -gt 0 ]; then
echo "β οΈ VALIDATION PASSED WITH WARNINGS: $warnings warnings" >> "$validation_report"
echo "β οΈ VALIDATION PASSED WITH WARNINGS for $(basename "$target_file")"
return 0
else
echo "β
VALIDATION PASSED: No issues found" >> "$validation_report"
echo "β
VALIDATION PASSED for $(basename "$target_file")"
return 0
fi
}validate_markdown_structure() {
local source_file=$1
local target_file=$2
local validation_report=$3
echo "" >> "$validation_report"
echo "=== STRUCTURE VALIDATION ===" >> "$validation_report"
# Headers count
local source_headers=$(grep -c '^#' "$source_file" 2>/dev/null || echo 0)
local target_headers=$(grep -c '^#' "$target_file" 2>/dev/null || echo 0)
if [ $source_headers -ne $target_headers ]; then
echo "β CRITICAL: Header mismatch (src:$source_headers, tgt:$target_headers)" >> "$validation_report"
critical_errors=$((critical_errors + 1))
else
echo "β
Headers preserved: $target_headers" >> "$validation_report"
fi
# Code blocks count
local source_code=$(grep -c '```' "$source_file" 2>/dev/null || echo 0)
local target_code=$(grep -c '```' "$target_file" 2>/dev/null || echo 0)
if [ $source_code -ne $target_code ]; then
echo "β οΈ WARNING: Code block mismatch (src:$source_code, tgt:$target_code)" >> "$validation_report"
warnings=$((warnings + 1))
else
echo "β
Code blocks preserved: $target_code" >> "$validation_report"
fi
# Links count
local source_links=$(grep -c '\[.*\](' "$source_file" 2>/dev/null || echo 0)
local target_links=$(grep -c '\[.*\](' "$target_file" 2>/dev/null || echo 0)
local link_diff=$((source_links - target_links))
if [ $link_diff -gt 5 ]; then
echo "β οΈ WARNING: Many links missing ($link_diff lost)" >> "$validation_report"
warnings=$((warnings + 1))
else
echo "β
Links mostly preserved (lost: $link_diff)" >> "$validation_report"
fi
}assess_translation_quality() {
local target_file=$1
local validation_report=$2
echo "" >> "$validation_report"
echo "=== QUALITY ASSESSMENT ===" >> "$validation_report"
# Check for product name preservation
if grep -q 'TiDB\|TiKV\|PD\|TiFlash' "$target_file"; then
echo "β
Product names preserved" >> "$validation_report"
else
echo "β οΈ WARNING: Product names not found" >> "$validation_report"
warnings=$((warnings + 1))
fi
# Check for untranslated English paragraphs
local english_paras=$(grep -cE '^[A-Z][a-zA-Z .,!?]{30,}$' "$target_file" 2>/dev/null || echo 0)
if [ $english_paras -gt 5 ]; then
echo "β οΈ WARNING: $english_paras potential untranslated paragraphs" >> "$validation_report"
warnings=$((warnings + 1))
else
echo "β
Minimal untranslated content: $english_paras paragraphs" >> "$validation_report"
fi
# Check for technical terms with explanations
if grep -qE '\([A-Za-z ]+\)' "$target_file"; then
echo "β
Technical terms with English explanations found" >> "$validation_report"
fi
}quick_validate() {
local target_file=$1
# Essential checks only
if [ ! -f "$target_file" ]; then
echo "β VALIDATION FAILED: File missing"
return 1
fi
if ! grep -q '[δΈ-ιΎ]' "$target_file" 2>/dev/null; then
echo "β VALIDATION FAILED: No Chinese content"
return 1
fi
if ! file "$target_file" | grep -q "UTF-8"; then
echo "β οΈ VALIDATION PASSED WITH WARNINGS: Encoding issue"
return 0
fi
echo "β
VALIDATION PASSED: Basic checks OK"
return 0
}- β VALIDATION PASSED: Perfect translation
β οΈ VALIDATION PASSED WITH WARNINGS: Acceptable with minor issues- β VALIDATION FAILED: Critical issues, needs retry
Validation agents are spawned automatically by main agent after each translation completion. Results are logged to .amazon_q_logs/validation_*.log.