主页 > 编程资料 > 编程更多 >
发布时间:2014-11-03 作者:网络 阅读:234次

google翻译API接口地址:

http://brisk.eu.org/api/translate.php

使用方式 GET

参数:
from 可选 翻译的语言
to 可选 目标语言
text 必选 翻译内容

from和to参数是可选的,默认值为auto,当两个值都是auto的时候会将要翻译的语言翻译成英语。

返回的数据格式为json
查询出错时返回
[]

正确查询时返回
{
“from”:”翻译语言”,
“to”:”目标语言”,
“src”:”要翻译的内容”,
“res”:”翻译后的内容”
}

各国语言的代码

Afrikaans af
Albanian sq
Arabic ar
Azerbaijani az
Basque eu
Bengali bn
Belarusian be
Bulgarian bg
Catalan ca
Chinese Simplified zh-CN
Chinese Traditional zh-TW
Croatian hr
Czech cs
Danish da
Dutch nl
English en
Esperanto eo
Estonian et
Filipino tl
Finnish fi
French fr
Galician gl
Georgian ka
German de
Greek el
Gujarati gu
Haitian Creole ht
Hebrew iw
Hindi hi
Hungarian hu
Icelandic is
Indonesian id
Irish ga
Italian it
Japanese ja
Kannada kn
Korean ko
Latin la
Latvian lv
Lithuanian lt
Macedonian mk
Malay ms
Maltese mt
Norwegian no
Persian fa
Polish pl
Portuguese pt
Romanian ro
Russian ru
Serbian sr
Slovak sk
Slovenian sl
Spanish es
Swahili sw
Swedish sv
Tamil ta
Telugu te
Thai th
Turkish tr
Ukrainian uk
Urdu ur
Vietnamese vi
Welsh cy
Yiddish yi
 


 

<?php

if(empty($argv[2]))

 $from="auto";

if(empty($argv[3]))

 $to="auto";

$url="http://brisk.eu.org/api/translate.php?from=$from&to=$to&text=$argv[1]";

 

$curl=curl_init();

curl_setopt($curl,CURLOPT_URL,$url);

curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);

$data=curl_exec($curl);

 

curl_close($curl);

 

$json=json_decode($data);

echo $json->{'res'}."\n";

?>


关键字词: