array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => json_encode($request),
),
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
return json_decode($response);
}
function lineCount($file_name)
{
$linecount = 0;
$handle = fopen($file_name, 'r');
while (!feof($handle)) {
$line = fgets($handle);
++$linecount;
}
fclose($handle);
return $linecount;
}
function addRequest($url, $postArray, $filesArray) {
// add import request. Return empty string if no error occurred
if ($filesArray['src_file']['error'] != 0 && $filesArray['src_file']['size'] > 0) {
return "Error uploading source file or no source file given.";
}
if ($filesArray['trg_file']['error'] != 0 && $filesArray['trg_file']['size'] > 0) {
return "Error uploading target file or no target file given.";
}
$srcFilePath = "/tmp/".uniqid("srcFile", true);
$trgFilePath = "/tmp/".uniqid("trgFile", true);
move_uploaded_file($filesArray['src_file']['tmp_name'], $srcFilePath);
move_uploaded_file($filesArray['trg_file']['tmp_name'], $trgFilePath);
$srcLineCount = lineCount($srcFilePath);
$trgLineCount = lineCount($trgFilePath);
if ($srcLineCount != $trgLineCount) {
return "Files have different number of lines ($srcLineCount and $trgLineCount).";
}
$request = array (
"operation" => "addRequest",
"sourceFilePath" => $srcFilePath,
"targetFilePath" => $trgFilePath,
"sourceLangId" => intval($postArray['src_lang_id']),
"targetLangId" => intval($postArray['trg_lang_id']),
"name" => $postArray['tm_name'],
"type" => intval($postArray['tm_type']),
"tmId" => intval($postArray['tm_id'])
);
$response = postJson($url, $request);
return "";
}
$url = 'http://@concordia_host@:@concordia_port@';
$errorMessage = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {
$errorMessage = addRequest($url, $_POST, $_FILES);
}
$statusesDictionary = array(
0 => "new",
1 => "processing - word alignment",
2 => "processing - adding to Concordia",
3 => "processing - regenerating index",
4 => "complete",
5 => "error"
);
$tmsData = postJson($url, array("operation" =>"getTmsInfo"));
$requestsData = postJson($url, array("operation" =>"getRequestsInfo"));
$languagesData = postJson($url, array("operation" =>"getLanguages"));
?>
Concordia
= $errorMessage ?>
Available translation memories:
Id |
Name |
Source language |
Target language |
tms as $tm) {
?>
= $tm->id ?> |
= $tm->name ?> |
= $tm->sourceLanguageCode ?> |
= $tm->targetLanguageCode ?> |
Import new translations
Latest import requests:
Id |
Name |
Source language |
Target language |
Status |
Type |
TM id |
Created |
requests as $request) {
?>
= $request->id ?> |
= $request->name ?> |
type == 0) {
echo $request->sourceLanguageCode;
} else {
echo "N/A";
}
?>
|
type == 0) {
echo $request->targetLanguageCode;
} else {
echo "N/A";
}
?>
|
= $statusesDictionary[$request->status] ?> |
type == 0) {
echo "new TM";
} else {
echo "extend TM";
}
?>
|
type == 0) {
echo "N/A";
} else {
echo $request->tmId;
}
?>
|
= $request->created ?> |