You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
2.6 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//<![CDATA[
var bdime_option = {
targets : ['translation']
}
zhcn='';
function getTran(){
$('#tran').html('');
$('#pinyin').html('');
strch=$("#translation").val();
if(strch==''){alert('Please input Chinese or English in the left box');return;}
$.ajax({
url:'/api/tran.php',
type:'POST',
data:{
'q':strch,
'len':strch.length
},
success: function(str){
str=eval("("+str+")");
if(strch.length>10){
//alert(str.trans_result[0].dst);
if(str.to=='en'){
//中->英
zhcn=str.trans_result[0].src;
}else if(str.to=='zh'){
//英->中
zhcn=str.trans_result[0].dst;
}
$('#tran').html(str.trans_result[0].dst);
zh2pinyin(zhcn);
getPYnpronounce(zhcn,'zh2en');
}else{
if(str.explains!=''){
$('#tran').html(str.tran+'<br /><br />explain<br /><br />'+str.explains);
}else{
$('#tran').html(str.tran);
}
//判断中英文
if(chkcharCode(strch)){
//中文
zhcn=str.query;
//词典没有获取到拼音
if(str.phonetic==''){
zh2pinyin(str.query);
getPYnpronounce(str.query,'zh2en');
}else{
$("#pinyin").html(str.phonetic);
getPYnpronounce(zhcn,'zh2en');
}
}else{
//英文
zhcn=str.tran;
zh2pinyin(zhcn);
var pyindata=$("#pinyin").html();
getPYnpronounce(zhcn,'zh2en');
}
}
}
});
$(".comm,#pinyin,#zhime").show();
}
function speak(){
$("#readtt").remove();
//模仿发音
if(zhcn=='' || !chkcharCode(zhcn)){return;}
str='<video controls="" autoplay="" name="media" id="readtt"><source src="http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text='+zhcn+'" type="audio/mp3"></video>';
$('body').append(str);
}
function zh2pinyin(zhstr){
if(!chkcharCode(zhstr)){
$('#pinyin').html('');
$("#zhime").html('');
return;
}
$.ajax({
url:'zh2pinyin.php',
data:{zh:zhstr},
type:'GET',
success: function(str){
$("#pinyin").html(str);
}
})
}
function getPYnpronounce(st,stype){
if(stype=='zh2en'){
$.ajax({
url:'zh2pinyin.php',
data:{zh:st},
type:'GET',
success: function(str){
getPYdata(str);
}
});
}else{
getPYdata(st);
}
}
function getPYdata(std){
$.ajax({
url:'/api/pinyin2en.php',
data:{pinyin:std},
type:"GET",
success: function(data){
$("#zhime").html(data)
//alert(data);
}
})
}
function chkcharCode(data){
//判断中英文:全为中文时为中文
data=data.toString();
var arr=data.match(/[^\x00-\x80]/g);
if(arr==null){
//英文
return false;
}else{
//中文
return true
if(arr.length==data.length){
return true;
}else{
return false;
}
}
}
//]]>