hide popup message if failure is handled - not sure what knock on effect this may...
[Pman.Core] / Pman.GoogleTranslate.js
index b55318b..0a4fcfb 100644 (file)
@@ -127,10 +127,24 @@ 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';
         
-        var ret = '';
+        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 + '/Core/GoogleTranslate.php',
@@ -140,7 +154,7 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) {
             params : {
                 text : str,
                 src  : src,
-                dest : dest,
+                dest : dest
             },
             success: function(o)
             {
@@ -152,46 +166,32 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) {
                     Roo.MessageBox.alert("Failure ", o.data.error.message);
                     return;
                 }
-//                Roo.MessageBox.alert("Success", "We logged in OK")
-                return o.translatedText;
+                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 ", 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);
             }
         });
         
-//        return ret;
-        
-//        
-//        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,
-//            []
-//        );
-        
-            
-        
     };