$dilTercihi = "en";
setcookie("dilTercihi", $dilTercihi, time() + (86400 * 30));
if (isset($_COOKIE['dilTercihi'])) {
$dilTercihi = $_COOKIE['dilTercihi'];
}
function translateText($text, $sourceLanguage, $targetLanguage) {
$apiKey = "YOUR_API_KEY"; // API anahtarınızı buraya ekleyin
$url = "https://translation.googleapis.com/language/translate/v2?key=" . $apiKey;
$postData = array(
'q' => $text,
'source' => $sourceLanguage,
'target' => $targetLanguage
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($postData)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);
if (isset($response['data']['translations'][0]['translatedText'])) {
return $response['data']['translations'][0]['translatedText'];
} else {
return false;
}
}