Çoklu Dil Sınıfı

Web Sitenize birden fazla dil seçeneği ekleyerek bu sınıfı kullanabilirsiniz.

PHP
63 lines
<?php
class cokluDil {
var $orjinal;
var $dil;
var $cevir;
var $sonid;
var $donustur;
var $dizi;
function baslat() {
$this->sonid = 0;
}
function AddDir($dizi, $dil) {
$this->dizi[$dil] = $dizi;
}
function Dir($dil) {
$dizi = $this->dizi[$dil];
return $dizi;
}
function donusturmeEkle($donustur,$dil) {
$this->donustur[$dil] = $donustur;
}
function donustur($dil) {
header("Content-Type: text/html; charset=" . $this->donustur[$dil] . "");
}
function ceviriEkle($orjinal,$dil,$cevir) {
if ($this->sonid >= 0) {
$id = ($this->sonid + 1);
}else{
$id = 0;
}
$this->orjinal[$id] = $orjinal;
$this->dil[$id] = $dil;
$this->cevir[$id] = $cevir;
$this->sonid = $id;
}
function cevir($orjinal,$dil) {
$sonid = $this->sonid;
$num = 1;
while($num <= $sonid) {
if ($this->dil[$num] == $dil && $this->orjinal[$num] == $orjinal) {
$result = $this->cevir[$num];
}
$num = $num + 1;
}
return $result;
}
}
$dil = new cokluDil;
$dil->baslat();
$dil->donusturmeEkle("iso-8859-9","tr");
$dil->donusturmeEkle("ISO-8859-1","en");
$dil->donustur("tr");
$dil->ceviriEkle("name","en","Name");
$dil->ceviriEkle("name","tr","İsim");
$dil->ceviriEkle("city","en","City");
$dil->ceviriEkle("city","tr","Şehir");
$dil->ceviriEkle("title","en","Title");
$dil->ceviriEkle("title","tr","Başlık");
print $dil->cevir("name","tr")."<br>";
print $dil->cevir("title","en")."<br>";
print $dil->cevir("city","tr")."<br>";
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
3 lines
İsim
Title
Şehir
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Yerelleştirme Sınıfı ile Dosyadan Farklı Dil Çevirilerini Almak

index.php

PHP
19 lines
<?php
class Yerellestirme{
var $ulke;
var $dil;
function Yerellestirme($dil,$ulke){
$this->ulke=$ulke;
$this->dil=$dil;
}
function Cevir($metin){
include ($this->dil)."_".($this->ulke).".inc";
return $$metin;
}
}
$En=new Yerellestirme("en","US");
print($En->Cevir("helloworld"));
echo "<br>";
$Tr=new Yerellestirme("tr","TR");
print($Tr->Cevir("helloworld"));
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

en_US.inc

PHP
3 lines
<?php
$helloworld="Hello World ";
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

tr_TR.inc

PHP
3 lines
<?php
$helloworld="Merhaba Dünya ";
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
2 lines
Hello World
Merhaba Dünya
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Google Translate Dil Çeviri Sınıfı

PHP
11 lines
<?php
class google{
static function translate($metin, $bundan, $buna) {
$f = file("http://translate.google.com/translate_t?text=" . urlencode($metin) . "&langpair=$bundan|$buna");
$i=implode(" ",$f);
preg_match("/TRANSLATED_TEXT='(.*?)';var ctr/si",$i,$sonuc);
echo $sonuc[1];
}
}
google::translate('Do you speak english?', 'en', 'tr');
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
İngilizce konuşabiliyor musun?
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Google Translate Dil Çeviri Sınıfı

PHP
11 lines
<?php
class googlecevir{
function cevir($metin, $yaziDili, $cevrilecekDil) {
$f = file("http://translate.google.com/translate_t?text=" . urlencode($metin) . "&langpair=$yaziDili|$cevrilecekDil");
preg_match('/<span id=result_box class="short_text"><span(.*?)>(.*?)<\/span><\/span>/si',$f[37],$sonuc);
return $sonuc[2];
}
}
$x = new googlecevir();
echo $x->cevir('Merhaba Dünya', 'tr', 'en');
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
Hello World
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Yandex Çeviri API v1.5

$apikey,$nereden,$nereye,$kelime değişkenlerini değiştirerek kullanabilirsiniz.

PHP
19 lines
<?php
header("Content-Type: text/html;charset=UTF-8");
//api key için https://translate.yandex.com/developers/keys adresinden create a new key butonuna tıklayınız.
$apikey = 'trnsl.1.1.xxxxxxxxTxxxxxxZ.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
//desteklenen diller için tıklayınız https://tech.yandex.com/translate/doc/dg/concepts/api-overview-docpage/
$nereden="en";//İngilizce için en
$nereye="tr";//Türkçe için tr
$kelime="Hello";
$url="https://translate.yandex.net/api/v1.5/tr.json/translate?key=".$apikey."&text=".urlencode($kelime)."&lang=".$nereden."-".$nereye."&format=plain";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result = json_decode(curl_exec($curl));
if ($result->code == 200) {
echo $result->text[0];
}
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
merhaba
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Mymemory Dil Çeviri Human API

$kelime, $nerden, $nereye değişkenlerini değiştirerek kullanabilirsiniz

PHP
9 lines
<?php
header("Content-Type: text/html;charset=UTF-8");
$kelime="I love you";
$nerden="English";
$nereye="Turkish";
$data = file_get_contents('http://mymemory.translated.net/en/'.$nerden.'/'.$nereye.'/'.urlencode($kelime));
preg_match_all('/class="text">(.*?)\</si',$data,$sonuc);
print_r($sonuc[1][1]);
?>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
ben seni seviyorum
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Itranslate4 Çeviri API

Not:Sunucu kaynaklı uzun kelimelerde çeviri süresi uzamaktadır.

PHP
45 lines
<?php
$basla=microtime();
header('Content-Type: text/html; charset=utf-8');
?><pre>
<form action="" method="post"><textarea name="text" maxlenght="500" cols="75" rows="5"></textarea><br>
<input type="submit" value="Çevir"/></form>
<?php
function it4cevir($text,$from,$to){
$data='{"src":"'.$from.'","trg":"'.$to.'","dat":"'.$text.'","dom":"","uid":"3ba5c1b2494446deac64500ff977171f","type":"text","trs_open_count":6,"trs_max_count":100}';
$url="http://itranslate4.eu/csa?func=translate&origin=text&data=".rawurlencode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);
$e=json_decode($html);
$data='{"tid":"'.$e->tid.'"}';
$r="1111111";
$a="9999999";
$t="111111111";
$b="999999999";
$url="http://itranslate4.eu/csa?func=translate_poll&rand=0.".rand($r,$a).rand($t,$b)."&data=".rawurlencode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);
$a=(json_decode($html));
if(isset($a->dat[0]->sgms[0])){
return ($a->dat[0]->sgms[0]->units[0]->text);
}else{
return it4cevir($text);
}
}
if(isset($_POST["text"])){
echo it4cevir($_POST["text"],"en","tr");//ingilizceden türkçeye çeviriyoruz
}
$son=microtime();
echo "<p>".abs($basla-$son)." saniyede yüklendi";
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Wordlingo Çeviri API

PHP
31 lines
function worldlingocevir($text,$from,$to){
$url='http://www.worldlingo.com/S000.1/api';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"wl_data=".rawurlencode($text)."&".
"wl_srclang=".$from."&".
"wl_trglang=".$to."&".
"wl_srcenc=UTF-8&".
"wl_trgenc=UTF-8&".
"wl_password=secret&".
"wl_mimetype=text/plain&".
"wl_opt=1&".
"wl_errorstyle=1&".
"wl_dictno=&".
"Submit=Submit"
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Kullanımı

 echo worldlingocevir("what is your name","en","tr");

Bayblon Çeviri API

PHP
22 lines
function babyloncevir($text,$from,$to){
//0=>İngilizce,1=>Fransız,2=>İtalyanca,6=>Alman,5=>Portekizce,3=>İspanyolca,15=>Arapça,99=>Catalan,344=>Kastilya,31=>Çek,10=>Çince (s),9=>Çince (t),43=>Danimarkalı,11=>Yunan,14=>İbranice,60=>Hintçe,30=>Macar,51=>Farsça,8=>Japon,12=>Kore,4=>Hollandalı,46=>Norveç,29=>Polonya,47=>Romanian,7=>Rus,48=>İsveç,13=>Türk,16=>Tayland,49=>Ukrayna,39=>Urduca
$url='http://translation.babylon.com/translate/babylon.php?v=1.0&q=';
$url.=rawurlencode($text).'&langpair='.$from.'%7C'.$to.'&callback=babylonTranslator.callback';
$url.='.&context=babylon.'.$from.'.'.$to.'._babylon_api_response';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);
preg_match("#{(.*?)}#si",$html,$s);
$j=json_decode($s[0],true);
return $j["translatedText"];
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Kullanımı

echo babyloncevir("what is your name",0,13);

Mymemory Çeviri API

PHP
18 lines
function mymemorycevir($text,$from,$to){
$url='http://api.mymemory.translated.net/get?q='.rawurlencode($text).'&langpair='.$from.'|'.$to;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close($ch);
$j=json_decode($html,true);
return $j["responseData"]["translatedText"];
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Kullanımı

PHP
1 lines
·echo mymemorycevir("What is your name","EN","TR");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX