2016-05-17 20:31:40 +05:00
< ? php
2016-05-25 17:10:29 +05:00
global $lang_obj ;
2018-01-15 12:28:30 +05:00
require_once 'GTvendor/autoload.php' ;
use Stichoza\GoogleTranslate\TranslateClient ;
$transClient = new TranslateClient (); // Default is from 'auto' to 'en'
2016-05-25 17:10:29 +05:00
2018-01-15 12:28:30 +05:00
class GoogleTranslator
2016-05-17 20:31:40 +05:00
{
/**
* Get access token
*
* @ return string
*/
2018-01-15 12:28:30 +05:00
public function get_access_token () {
return false ;
2016-05-17 20:31:40 +05:00
}
/**
* Translate text to a specified language
*
* @ param string $text
* @ param string $to language to be translated to
* @ param string $from language of text
* @ return string Translated text
*/
2018-01-15 12:28:30 +05:00
public function translate ( $text , $to , $from = 'en' ) {
global $transClient ;
$transClient -> setSource ( $from ); // Translate from English
$transClient -> setTarget ( $to ); // Translate to Georgian
$transClient -> setUrlBase ( 'http://translate.google.cn/translate_a/single' ); // Set Google Translate URL base (This is not necessary, only for some countries)
2018-04-10 16:10:37 +05:00
// checkmate
$text = str_replace ( " %s " , " _c_b_ " , $text );
2018-01-15 12:28:30 +05:00
$phraseTranslated = $transClient -> translate ( $text );
2018-04-10 16:10:37 +05:00
$phraseTranslated = str_replace ( " _c_b_ " , " %s " , $phraseTranslated );
// checkmate
2018-01-15 12:28:30 +05:00
return $phraseTranslated ;
2016-05-17 20:31:40 +05:00
}
/**
* Translate text to specified languages
*
* @ param string $text
* @ param string $from language of text
* @ param array $tos languages to be translated to
* @ return array Translations of the text to given languages
*/
2016-05-25 17:10:29 +05:00
public function multiTranslate ( $text , $from , $tos ) {
2018-01-15 12:28:30 +05:00
return false ;
2016-05-17 20:31:40 +05:00
}
/**
* Detect the language of a given text
*
* @ param String $text
* @ return String Language of text
*/
2016-05-25 17:10:29 +05:00
public function detectLang ( $text ) {
2018-01-15 12:28:30 +05:00
return false ;
2016-05-17 20:31:40 +05:00
}
}
?>