protected function prepareSegment($seg, $trans_unit_translation = "")
 {
     $end_tags = "";
     //We don't need transform/sanitize from wiew to xliff because the values comes from Database
     //QA non sense for source/source check, until source can be changed. For now SKIP
     if (is_null($seg['translation']) || $seg['translation'] == '') {
         $translation = $seg['segment'];
     } else {
         $translation = $seg['translation'];
         if (empty($seg['locked'])) {
             //consistency check
             $check = new QA($seg['segment'], $translation);
             $check->performTagCheckOnly();
             if ($check->thereAreErrors()) {
                 $translation = '|||UNTRANSLATED_CONTENT_START|||' . $seg['segment'] . '|||UNTRANSLATED_CONTENT_END|||';
                 Log::doLog("tag mismatch on\n" . print_r($seg, true) . "\n(because of: " . print_r($check->getErrors(), true) . ")");
             }
         }
     }
     if ($seg['mrk_id'] !== null) {
         $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>";
     }
     $trans_unit_translation .= $seg['prev_tags'] . $translation . $end_tags . $seg['succ_tags'];
     return $trans_unit_translation;
 }
Exemple #2
0
    public function testBadXml()
    {
        //PHASE 3 check for particular tag mismatch: unclosed x tag <x id="231">
        $source_seg = <<<SRC
<g id="pt235"><g id="pt236"> <x id="abc/></g></g> <g id="pt238"><g id="pt239">Elsa sur son ordinateur tape des lignes de code quand sa colocataire, Joy, entre dans sa chambre.</g></g>
SRC;
        $target_seg = <<<TRG
<g id="pt235"><g id="pt236"> </g></g> <g id="pt238"><g id="pt239">Elsa's on her computer typing lines of code when her roommate, Joy, enters the room.</g></g>
TRG;
        $check = new QA($source_seg, $target_seg);
        $check->performTagCheckOnly();
        $this->assertTrue($check->thereAreErrors());
        $errors = $check->getErrors();
        $this->assertCount(1, $errors);
        $this->assertAttributeEquals(1000, 'outcome', $errors[0]);
        $this->assertRegExp('/ 1 /', $check->getErrorsJSON());
        $this->assertEquals('[{"outcome":1000,"debug":"Tag mismatch ( 1 )"}]', $check->getWarningsJSON());
        $this->assertEquals('[{"outcome":1000,"debug":"Tag mismatch ( 1 )"}]', $check->getErrorsJSON());
    }
 //preg_replace all x tags <x not closed > inside suggestions with correctly closed
 $suggestion = preg_replace('|<x([^/]*?)>|', '<x\\1/>', $suggestion);
 $suggestion_match = $matches[0]['match'];
 $suggestion_json = json_encode($matches);
 $suggestion_source = $matches[0]['created_by'];
 $equivalentWordMapping = json_decode($payable_rates, true);
 $new_match_type = getNewMatchType($tm_match_type, $fast_match_type, $equivalentWordMapping, empty($matches[0]['memory_key']));
 //echo "sid is $sid ";
 $eq_words = $equivalentWordMapping[$new_match_type] * $raw_wc / 100;
 $standard_words = $eq_words;
 if ($new_match_type == 'MT') {
     $standard_words = $equivalentWordMapping["NO_MATCH"] * $raw_wc / 100;
 }
 !empty($matches[0]['sentence_confidence']) ? $mt_qe = floatval($matches[0]['sentence_confidence']) : ($mt_qe = null);
 $check = new QA($text, $suggestion);
 $check->performTagCheckOnly();
 //log::doLog($check->getErrors(true));
 echo "--- (child {$my_pid}) : sid={$sid} --- \$tm_match_type={$tm_match_type}, \$fast_match_type={$fast_match_type}, \$new_match_type={$new_match_type}, \$equivalentWordMapping[\$new_match_type]=" . $equivalentWordMapping[$new_match_type] . ", \$raw_wc={$raw_wc},\$standard_words={$standard_words},\$eq_words={$eq_words}\n";
 if ($check->thereAreErrors()) {
     $err_json = $check->getErrorsJSON();
 } else {
     $err_json = '';
 }
 echo "--- (child {$my_pid}) : sid={$sid} --- \$tm_match_type={$tm_match_type}, \$fast_match_type={$fast_match_type}, \$new_match_type={$new_match_type}, \$equivalentWordMapping[\$new_match_type]=" . $equivalentWordMapping[$new_match_type] . ", \$raw_wc={$raw_wc},\$standard_words={$standard_words},\$eq_words={$eq_words}\n";
 $tm_data = array();
 $tm_data['id_job'] = $jid;
 $tm_data['id_segment'] = $sid;
 $tm_data['suggestions_array'] = $suggestion_json;
 $tm_data['suggestion'] = $suggestion;
 $tm_data['suggestion_match'] = $suggestion_match;
 $tm_data['suggestion_source'] = $suggestion_source;