Beispiel #1
0
 /**
  * Export Job as Tmx File
  *
  * @param $jid
  * @param $jPassword
  * @param $sourceLang
  * @param $targetLang
  *
  * @return SplTempFileObject $tmpFile
  *
  */
 public function exportJobAsCSV($jid, $jPassword, $sourceLang, $targetLang)
 {
     $tmpFile = new SplTempFileObject(15 * 1024 * 1024);
     $csv_fields = array("Source: {$sourceLang}", "Target: {$targetLang}");
     $tmpFile->fputcsv($csv_fields);
     $result = getTranslationsForTMXExport($jid, $jPassword);
     foreach ($result as $k => $row) {
         $row_array = array($row['segment'], $row['translation']);
         $tmpFile->fputcsv($row_array);
     }
     $tmpFile->rewind();
     return $tmpFile;
 }
Beispiel #2
0
    /**
     * Export Job as Tmx File
     *
     * @param $jid
     * @param $jPassword
     * @param $sourceLang
     * @param $targetLang
     *
     * @return SplTempFileObject $tmpFile
     *
     */
    public function exportJobAsTMX($jid, $jPassword, $sourceLang, $targetLang)
    {
        $tmpFile = new SplTempFileObject(15 * 1024 * 1024);
        $tmpFile->fwrite('<?xml version="1.0" encoding="UTF-8"?>
<tmx version="1.4">
    <header
            creationtool="Matecat-Cattool"
            creationtoolversion="' . INIT::$BUILD_NUMBER . '"
	    o-tmf="Matecat"
            creationid="Matecat"
            datatype="plaintext"
            segtype="sentence"
            adminlang="en-US"
            srclang="' . $sourceLang . '"/>
    <body>');
        switch ($this->output_type) {
            case 'translation':
                $result = getTranslationsForTMXExport($jid, $jPassword);
                break;
            case 'mt':
                $result = getMTForTMXExport($jid, $jPassword);
                break;
            case 'tm':
                $result = getTMForTMXExport($jid, $jPassword);
                break;
            default:
                $result = getTranslationsForTMXExport($jid, $jPassword);
                break;
        }
        foreach ($result as $k => $row) {
            $dateCreate = new DateTime($row['translation_date'], new DateTimeZone('UTC'));
            $tmx = '
    <tu tuid="' . $row['id_segment'] . '" creationdate="' . $dateCreate->format('Ymd\\THis\\Z') . '" datatype="plaintext" srclang="' . $sourceLang . '">
        <prop type="x-MateCAT-id_job">' . $row['id_job'] . '</prop>
        <prop type="x-MateCAT-id_segment">' . $row['id_segment'] . '</prop>
        <prop type="x-MateCAT-filename">' . $row['filename'] . '</prop>
        <tuv xml:lang="' . $sourceLang . '">
            <seg>' . htmlspecialchars($row['segment']) . '</seg>
        </tuv>
        <tuv xml:lang="' . $targetLang . '">
            <seg>' . htmlspecialchars($row['translation']) . '</seg>
        </tuv>
    </tu>
';
            $tmpFile->fwrite($tmx);
        }
        $tmpFile->fwrite("\n    </body>\n</tmx>");
        $tmpFile->rewind();
        return $tmpFile;
    }