<?php
/**
 * Script to find Arabic translation keys that have English values
 * and fix them by finding proper Arabic translations
 */

$ar = include 'includes/translations/ar.php';
$en = include 'includes/translations/en.php';

// Find keys in Arabic that still have English values (not translated)
$notTranslated = [];
foreach ($ar as $key => $value) {
    // Check if value looks like English (contains mostly ASCII letters)
    // Skip keys that are intentionally English (like hospital_name_en, system_name_en, etc.)
    if (preg_match('/^[A-Za-z0-9\s\-_\(\)\/\.,!?:;\'\"]+$/', $value) 
        && !in_array($key, ['hospital_name_en', 'system_name_en', 'system_name', 'hospital_name'])
        && !preg_match('/^(ar|en|rtl|ltr|ICS|ICU|CCU|DAMA|Excel|PDF|PHP|MRN|KPI|URL|ID|ISO|AWaRe|Access|Watch|Reserve|IV|IM)$/', $value)
    ) {
        $notTranslated[$key] = $value;
    }
}

echo "Keys with English values in ar.php: " . count($notTranslated) . "\n\n";

// Find keys missing entirely from Arabic
$missing = array_diff_key($en, $ar);
echo "Keys missing entirely from ar.php: " . count($missing) . "\n\n";

// Show sample of not-translated
echo "=== Sample of keys with English values ===\n";
$i = 0;
foreach ($notTranslated as $key => $value) {
    echo "'$key' => '$value'\n";
    if (++$i >= 20) { echo "...\n"; break; }
}
