X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=Pman.GoogleTranslate.js;h=0a4fcfbf672e0f6609abc1ecb0434fb73b9198a9;hp=2778ee24f2c4255a4aa5716f40dac1275f95c5c8;hb=586e4eb470252d837ba18b67e4c3c1702131fd1d;hpb=a535e6af489416c6d2d9c34dc3f44f15965f2e82 diff --git a/Pman.GoogleTranslate.js b/Pman.GoogleTranslate.js index 2778ee24..0a4fcfbf 100644 --- a/Pman.GoogleTranslate.js +++ b/Pman.GoogleTranslate.js @@ -127,61 +127,71 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) { src = src.replace('_','-'); dest = dest.replace('_','-'); // google does not recognize HK... - if (src == 'zh-HK') src = 'zh-TW'; - if (dest == 'zh-HK') dest = 'zh-TW'; - + + switch(dest){ + case 'zh': + src = 'zh-CN'; + break; + case 'zh-HK': + src = 'zh-TW'; + break; + } + + switch(dest){ + case 'zh': + dest = 'zh-CN'; + break; + case 'zh-HK': + dest = 'zh-TW'; + break; + } + new Pman.Request({ - url : baseURL + '/Roo/GoogleTranslate.php', + url : baseURL + '/Core/GoogleTranslate.php', method :'POST', mask : 'Translating', maskEl : document.body, params : { text : str, src : src, - dest : dest, + dest : dest }, success: function(o) { if (!o.data) { return o; } -// Roo.MessageBox.alert("Success", "We logged in OK") - return o.data.translations[0].translatedText; + if(typeof(o.data.error) != 'undefined'){ + Roo.get(document.body).unmask(); + Roo.MessageBox.alert("Failure ", o.data.error.message); + return; + } + if(typeof(o.data.translations[0].translatedText) == 'undefined'){ + Roo.MessageBox.alert("Failure ", "Does not found the translated text."); + } + cb(o.data.translations[0].translatedText); }, failure: function (res) { Roo.log(res); - Roo.MessageBox.alert("Failure", "Failed?") + if (!res.data) { + return res; + } + + if(typeof(res.data.error) != 'undefined'){ + Roo.get(document.body).unmask(); + Roo.MessageBox.alert("Failure ", res.data.error.message); + return; + } + + if(typeof(res.data.translations[0].translatedText) == 'undefined'){ + Roo.MessageBox.alert("Failure ", "Does not found the translated text."); + } + cb(res.data.translations[0].translatedText); + + //Roo.MessageBox.alert("Failure ", res.message); } }); - x.load( - { - key : Pman.GoogleTranslate.key, - // v: '1.0', - q : str, - source : src, - target : dest - //langpair : src + '|' +dest - }, // end params. - { // reader - readRecords : function (o) { - Roo.log(o); - if (!o.data) { - return o; - } - return o.data.translations[0].translatedText; - //return escapeDecode(o.data.translations[0].translatedText); - } - }, - function (result) { - cb(result); - }, - this, - [] - ); - - - };