| Server IP : 64.202.187.69 / Your IP : 216.73.216.17 Web Server : Apache System : Linux 69.187.202.64.host.secureserver.net 3.10.0-1160.144.1.el7.tuxcare.els6.x86_64 #1 SMP Fri May 29 16:22:24 UTC 2026 x86_64 User : transmarket ( 1001) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/transmarket/testtranslator/ |
Upload File : |
<?php
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
ini_set('display_errors',1);
//error_reporting(E_ALL);
error_reporting( E_ALL );
include 'SimpleXLSXGen.php';
$row = 1;
function translate($str='') {
//$data = array();
$ch = curl_init();
//curl -X POST "https://libretranslate.com/translate" -H "accept: application/json" -H "Content-Type: " -d "q=Hello&source=en&target=es&format=text&api_key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
//$str = 'Resumption of new session';
curl_setopt($ch, CURLOPT_URL, 'https://libretranslate.com/translate');
//curl_setopt($ch, CURLOPT_URL, 'http://169.255.36.95:5000/translate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post[ 'source' ] = 'en';
$post[ 'target' ] = 'es';
$post[ 'format' ] = 'text';
$post[ 'q' ] = $str;
//echo http_build_query( $post );
//curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query(json_encode( $post ) ) );
$post_str = http_build_query($post);
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
$result = curl_exec($ch);
// print_r( $result );
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return json_decode($result) ;
}
echo "Reslut ";
print_r(translate('Hello'));
die();
if ( ( $handle = fopen("EN_ES_4.csv", "r")) !== FALSE) {
$trns[] = ['English', 'Spanish', 'Api' ];
while ( ( $data = fgetcsv($handle, 1000, "," ) ) !== FALSE ) {
$num = count($data);
$row++;
// echo "col num is 0 -".$data[0] . "<br />\n";
if( $data[0]!= '' ){
//echo "in if<br>";
$translated_obj = translate($data[0]);
//print_r( $translated_obj );
//json_encode( $translated_obj );
echo "<hr />".$data[0]."-".$data[1]."-".$translated_obj->data;
$trns[] = [$data[0], $data[1], $translated_obj->data];
}else{
echo "can not translate blank value";
}
// }
}
$xlsx = SimpleXLSXGen::fromArray( $trns );
$xlsx->saveAs('translated.xlsx'); // or downloadAs('books.xlsx') or $xlsx_content = (string) $xlsx
die();
fclose($handle);
}
echo "in translte";
////die();