function Translate($word, $conversion = 'hi_to_en') { $translator = new MicrosoftTranslator("ZWXY16Y45VGP/tLUWwkikzop8iuzPBBcqzhtqpO4+zU"); $translator->translate("en", "hi", $word); $data = json_decode($translator->response->jsonResponse, true); return strip_tags($data["translation"]); }
/** * Get the translation from a given string using Bing Translate API */ public function getBingTranslation() { if (!AccountManager::getInstance()->isLogged()) { return JsonResponseBuilder::failure(); } $str = $this->getRequestVariable('str'); $lang = AccountManager::getInstance()->vcsLang; $translation = false; $str = str_replace("\n", "[@]", $str); $bing = new MicrosoftTranslator("0Iwzej5BJeHK/2nvHh7/uJyHLhmnyFJEAuOYOfJ1QLg="); $bing->translate('en', $lang, $str); $bing->response->jsonResponse; preg_match("/<string xmlns=\"(.[^\"]*)\">(.*)?<\\/string>/e", $bing->response->translation, $match); // Replace new line mark $translation = str_replace("[@]", "<br>", $match[2]); // Few substitutions $translation = str_replace("&", "&", $translation); $translation = str_replace("& ", "&", $translation); $translation = str_replace("'", "'", $translation); $translation = str_replace(""", '"', $translation); $translation = str_replace("<", '<', $translation); $translation = str_replace(">", '>', $translation); return JsonResponseBuilder::success(array('translation' => $translation)); }
<?php require_once dirname(__FILE__) . "/MicrosoftTranslator.php"; // Load MicrosoftTranslator Class ... $MicrosoftTranslator = new MicrosoftTranslator(); // Call MicrosoftTranslator Class $array = array('username' => '{live login}', 'key' => '{Azure account key}', 'text' => '{text}', 'to' => '{translate Language}', 'from' => '{Text Language}'); $MicrosoftTranslator->set($array); // Set All Variables As Array echo $MicrosoftTranslator->translate(); // translate output
<?php /** * This file will retuen JSON response */ require_once 'config.inc.php'; require_once 'class/ServicesJSON.class.php'; require_once 'class/MicrosoftTranslator.class.php'; $translator = new MicrosoftTranslator(ACCOUNT_KEY); $text_to_translate = $_REQUEST["text"]; $to = $_REQUEST['to']; //$from = $_REQUEST['from']; //NOTICE:There is no "from" from URL; $from = ''; $format = ''; $translator->translate($from, $to, $text_to_translate, $format); echo $translator->response->jsonResponse;
<?php /** * This file will retuen JSON response */ require_once 'config.inc.php'; require_once 'class/ServicesJSON.class.php'; require_once 'class/MicrosoftTranslator.class.php'; $translator = new MicrosoftTranslator(ACCOUNT_KEY); $text_to_translate = $_REQUEST['text']; $to = $_REQUEST['to']; $from = $_REQUEST['from']; $translator->translate($from, $to, $text_to_translate); echo $translator->response->jsonResponse;