DataObjects/core.sql
[Pman.Core] / Pman.GoogleTranslate.js
index d29b956..1978ccd 100644 (file)
@@ -24,10 +24,15 @@ Pman.GoogleTranslate = function(str, src, dest, cb, force) {
                 url : baseURL + '/Core/GoogleKey',
                 success : function(data)
                 {
-                    Pman.GoogleTranslate.key = data.key;
+                    Pman.GoogleTranslate.key = data.data;
                     
                     Pman.GoogleTranslate(str, src, dest, cb, force);
                     
+                },
+                failure : function() {
+                    Roo.log("Google key fetch failed");
+                    // do not display error message...
+                    return true;
                 }
                 
                 
@@ -112,13 +117,21 @@ 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'
             
             
         });
         
+        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';
+     
+         
+        
         x.load(
             {
                 key :  Pman.GoogleTranslate.key,
@@ -130,10 +143,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) {