-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translator.php
39 lines (35 loc) · 1.12 KB
/
Translator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
class Translator
{
protected $translated;
protected $processor;
function __construct($apiKey) {
$this->processor = new CurlProcessor;
$this->processor->curlInit(new Configurator($apiKey));
}
function translate($sourceLang, $textToTranslate, $targetLang, $contentString=NULL) {
$body = "text=" . $textToTranslate . "&source_lang=$sourceLang&target_lang=" . $targetLang;
$this->processor->curlBody($body);
$this->translated = $this->processor->curlExecution();
if(!$this->processor->curlErrorHandling()){
if($contentString) {
return str_replace($textToTranslate . "',",
$this->translated . "', #". $textToTranslate,
$contentString);
}
else{
return $this->translated;
}
}
else{
return $this->processor->curlErrorHandling();
}
}
function display()
{
echo $this->translated;
}
function closeRequest(){
$this->processor->closeRequest();
}
}