Pman.GoogleTranslate.js
[Pman.Core] / Pman.GoogleTranslate.js
index fe6061d..98834e1 100644 (file)
@@ -28,6 +28,11 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) {
                     
                     Pman.GoogleTranslate(str, src, dest, cb, force);
                     
+                },
+                failure : function() {
+                    Roo.log("Google key fetch failed");
+                    // do not display error message...
+                    return true;
                 }
                 
                 
@@ -112,19 +117,39 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) {
                 
           
         var x = new Roo.data.ScriptTagProxy({ 
-            url:   'https://www.googleapis.com/language/translate/v2/languages',
+            url:   'https://www.googleapis.com/language/translate/v2',
                   //'http://ajax.googleapis.com/ajax/services/language/translate', 
             callbackParam : 'callback'
             
             
         });
-        /// fix some of the languages..
-        switch (target) {
-                case 'zh-CN' : target = 'zh'; break;
-                case 'zh-HK' : target = 'zh-TW'; break;
-                    
-        }
-         
+        
+        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';
+     
+        new Pman.Request({
+            url : baseURL + '/Roo/GoogleTranslate.php',
+            method :'POST',
+            mask : 'Translating',
+            maskEl : document.body,
+            params : {
+                text : str,
+                src  : src,
+                dest : dest,
+            },
+            success: function()
+            {
+                Roo.MessageBox.alert("Success", "We logged in OK")
+
+            },
+            failure: function (res) {
+                Roo.log(res);
+                Roo.MessageBox.alert("Failure", "Failed?")
+            }
+        });
         
         x.load(
             {
@@ -137,10 +162,12 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) {
             }, // end params.
             { // reader
                 readRecords : function (o) {
-                    if (!o.responseData) {
+                    Roo.log(o);
+                    if (!o.data) {
                         return o;
                     }
-                    return escapeDecode(o.responseData.translatedText);
+                    return o.data.translations[0].translatedText;
+                    //return escapeDecode(o.data.translations[0].translatedText);
                 }
             }, 
             function (result) {