Pman.GoogleTranslate.js
[Pman.Core] / Pman.GoogleTranslate.js
index c36a29d..186bb30 100644 (file)
@@ -127,6 +127,8 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) {
         src = src.replace('_','-');
         dest = dest.replace('_','-');
         // google does not recognize HK...
+        if (src  == 'zh')  src = 'zh-CN';
+        if (dest  == 'zh')  dest = 'zh-CN';
         if (src  == 'zh-HK')  src = 'zh-TW';
         if (dest == 'zh-HK') dest = 'zh-TW';
         
@@ -142,23 +144,41 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) {
             },
             success: function(o)
             {
-                Roo.log('in?');
+//                Roo.log('in?');
                 if (!o.data) {
                     return o;
                 }
-                Roo.log('in2?');
+//                Roo.log('in2?');
                 if(typeof(o.data.error) != 'undefined'){
                     Roo.get(document.body).unmask();
                     Roo.MessageBox.alert("Failure ", o.data.error.message);
                     return;
                 }
-                Roo.log('in3?');
-                cb(o.data.translatedText);
+//                Roo.log('in3?');
+                if(typeof(o.data.translations[0].translatedText) == 'undefined'){
+                    Roo.MessageBox.alert("Failure ", "Does not found the translated text.");
+                }
+                cb(o.data.translations[0].translatedText);
 //                ret = o.data.translatedText;
             },
             failure: function (res) {
                 Roo.log(res);
-                Roo.MessageBox.alert("Failure ", res.data.error.message);
+                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);
             }
         });
 //        Roo.log(ret);