CURLOPT_HTTPHEADER => [
'X-API-Key: ' . $apiKey,
'Accept: application/json'
],
CURLOPT_POSTFIELDS => [
'file' => new CURLFile(realpath($tempJson), 'application/json', $id . '.json'),
'source_lang' => 'en',
'target_lang' => $id,
]
]);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); // كود حالة الاستجابة
$curlError = curl_error($curl);
curl_close($curl);
if(file_exists($tempJson)) unlink($tempJson);
// 3. تحليل الاستجابة
$result = json_decode($response, true);
if($httpCode == 200 && isset($result['success']) && $result['success']) {
$translatedData = $result['translated'];
// إعادة بناء الملف بنفس طريقتك الأصلية
$phpContent = " $value) {
$cleanValue = addslashes($value); // حماية القيم من الرموز الخاصة
$phpContent .= "\$lang['$key'] = \"$cleanValue\";\n";
}
$phpContent .= "?>";
file_put_contents($filePath, $phpContent);
echo "
✅ تمت الترجمة بنجاح! تم تحديث $id.php.
";
} else {
// إظهار تفاصيل الخطأ للحل
$errorDesc = $result['error'] ?? ($curlError ?: "كود الاستجابة: $httpCode");
echo "
❌ فشل الترجمة: $errorDesc
";
// تنبيه بسيط للمطور
if($httpCode == 0) echo "
تنبيه: السيرفر لا يستطيع الوصول للرابط، تأكد من اتصال السيرفر بالإنترنت.
";
}
} else {
echo "
❌ خطأ: المتغير \$lang غير موجود في $id.php
";
}
}
}
if($b == "set_default") {
$id = $_GET['id'];
if(!file_exists("languages/$id.php")) {
header("Location: ?a=languages");
}
?>
query("UPDATE settings SET default_language='$id'");
echo "New default language is $id.";
?>
$lang_name already exists."; }
else {
$contents = '$v) {
$contents .= '$lang["'.$k.'"] = "'.$v.'";
';
}
$contents .= '?>';
$update = file_put_contents("languages/$lang_name.php",$contents);
if($update) {
echo "Language $lang_name was added successfully.";