GoogleTranslate.php
authorChris <chris@roojs.com>
Wed, 2 Apr 2014 10:09:29 +0000 (18:09 +0800)
committerChris <chris@roojs.com>
Wed, 2 Apr 2014 10:09:29 +0000 (18:09 +0800)
GoogleTranslate.php

index a9e22bc..8b4585e 100644 (file)
@@ -10,6 +10,54 @@ require_once 'Pman.php';
 class Pman_Core_GoogleTranslate extends Pman
 {
     //put your code here
+    function getAuth()
+    {
+        
+        $au = $this->getAuthUser();
+        if (!$au) {
+            $this->jerrAuth("only authenticated users");
+        }
+        
+        $this->authUser = $au;
+    }
+    function get() {
+        // for testing..
+        return $this->post();
+    }
+    
+    function post()
+    {
+        $pc = HTML_FlexyFramework::get()->Pman_Core;
+        if (empty($pc['googlekey'])) {
+            $this->jerr("Google API Key not configured");
+        }
+        
+        $apiKey = $pc['googlekey'];
+    
+        $text = 'Hello world!';
+        $param = array(
+            'key' => $pc['googlekey'],
+            'q' => rawurlencode($_REQUEST['text']),
+            'source' => $_REQUEST['src'],
+            'target' => $_REQUEST['dest']
+        );
+        
+        $url = 'https://www.googleapis.com/language/translate/v2?key='.
+                $apiKey.
+                '&q='.
+                rawurlencode($text).
+                '&source=en&target=fr';
+
+        $handle = curl_init($url);
+        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+        $response = curl_exec($handle);                 
+        $responseDecoded = json_decode($response, true);
+        curl_close($handle);
+    
+        
+        $this->jdata($key);
+        
+    }
     
     
 }