@@ -8,20 +8,20 @@ |
||
| 8 | 8 | * |
| 9 | 9 | * @return array|null |
| 10 | 10 | */ |
| 11 | - public function check( ?array $tmp = [] ): ?array { |
|
| 11 | + public function check(?array $tmp = []): ?array { |
|
| 12 | 12 | $fileType = []; |
| 13 | 13 | |
| 14 | - if ( isset( $tmp[ 0 ] ) ) { |
|
| 15 | - preg_match( '#tool-id\s*=\s*"matecat-converter(\s+([^"]+))?"#i', $tmp[ 0 ], $matches ); |
|
| 16 | - if ( !empty( $matches ) ) { |
|
| 17 | - $fileType[ 'proprietary' ] = false; |
|
| 18 | - $fileType[ 'proprietary_name' ] = 'MateCAT Converter'; |
|
| 19 | - $fileType[ 'proprietary_short_name' ] = 'matecat_converter'; |
|
| 20 | - if ( isset( $matches[ 2 ] ) ) { |
|
| 21 | - $fileType[ 'converter_version' ] = $matches[ 2 ]; |
|
| 14 | + if (isset($tmp[0])) { |
|
| 15 | + preg_match('#tool-id\s*=\s*"matecat-converter(\s+([^"]+))?"#i', $tmp[0], $matches); |
|
| 16 | + if (!empty($matches)) { |
|
| 17 | + $fileType['proprietary'] = false; |
|
| 18 | + $fileType['proprietary_name'] = 'MateCAT Converter'; |
|
| 19 | + $fileType['proprietary_short_name'] = 'matecat_converter'; |
|
| 20 | + if (isset($matches[2])) { |
|
| 21 | + $fileType['converter_version'] = $matches[2]; |
|
| 22 | 22 | } else { |
| 23 | 23 | // First converter release didn't specify version |
| 24 | - $fileType[ 'converter_version' ] = '1.0'; |
|
| 24 | + $fileType['converter_version'] = '1.0'; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | return $fileType; |
@@ -8,22 +8,22 @@ |
||
| 8 | 8 | * |
| 9 | 9 | * @return array|null |
| 10 | 10 | */ |
| 11 | - public function check( ?array $tmp = [] ): ?array { |
|
| 11 | + public function check(?array $tmp = []): ?array { |
|
| 12 | 12 | $fileType = []; |
| 13 | 13 | |
| 14 | - if ( isset( $tmp[ 0 ] ) ) { |
|
| 15 | - preg_match( '|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr( $tmp[ 0 ], 0, 1000 ), $versionMatches ); |
|
| 16 | - preg_match( '|<xliff.*?\sxmlns\s?=\s?["\']urn:oasis:names:tc:xliff:document:(.*?)["\']|si', substr( $tmp[ 0 ], 0, 1000 ), $xmlnsMatches ); |
|
| 14 | + if (isset($tmp[0])) { |
|
| 15 | + preg_match('|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr($tmp[0], 0, 1000), $versionMatches); |
|
| 16 | + preg_match('|<xliff.*?\sxmlns\s?=\s?["\']urn:oasis:names:tc:xliff:document:(.*?)["\']|si', substr($tmp[0], 0, 1000), $xmlnsMatches); |
|
| 17 | 17 | |
| 18 | - if ( !empty( $versionMatches ) && !empty( $xmlnsMatches ) ) { |
|
| 19 | - $version = $versionMatches[ 1 ]; |
|
| 20 | - $xmlns = $xmlnsMatches[ 1 ]; |
|
| 18 | + if (!empty($versionMatches) && !empty($xmlnsMatches)) { |
|
| 19 | + $version = $versionMatches[1]; |
|
| 20 | + $xmlns = $xmlnsMatches[1]; |
|
| 21 | 21 | |
| 22 | - if ( $version === $xmlns && $version >= 2 ) { |
|
| 23 | - $fileType[ 'proprietary' ] = false; |
|
| 24 | - $fileType[ 'proprietary_name' ] = 'Xliff v' . $version . ' File'; |
|
| 25 | - $fileType[ 'proprietary_short_name' ] = 'xliff_v2'; |
|
| 26 | - $fileType[ 'converter_version' ] = '2.0'; |
|
| 22 | + if ($version === $xmlns && $version >= 2) { |
|
| 23 | + $fileType['proprietary'] = false; |
|
| 24 | + $fileType['proprietary_name'] = 'Xliff v' . $version . ' File'; |
|
| 25 | + $fileType['proprietary_short_name'] = 'xliff_v2'; |
|
| 26 | + $fileType['converter_version'] = '2.0'; |
|
| 27 | 27 | |
| 28 | 28 | return $fileType; |
| 29 | 29 | } |
@@ -8,5 +8,5 @@ |
||
| 8 | 8 | * |
| 9 | 9 | * @return array|null |
| 10 | 10 | */ |
| 11 | - public function check( ?array $tmp = [] ): ?array; |
|
| 11 | + public function check(?array $tmp = []): ?array; |
|
| 12 | 12 | } |
@@ -9,12 +9,12 @@ discard block |
||
| 9 | 9 | /** |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
| 12 | - private static array $versions_1 = [ '1.0', '1.1', '1.2' ]; |
|
| 12 | + private static array $versions_1 = ['1.0', '1.1', '1.2']; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * @var array |
| 16 | 16 | */ |
| 17 | - private static array $versions_2 = [ '2.0', '2.1' ]; |
|
| 17 | + private static array $versions_2 = ['2.0', '2.1']; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @param string $xliffContent |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | * @throws NotSupportedVersionException |
| 24 | 24 | * @throws NotValidFileException |
| 25 | 25 | */ |
| 26 | - public static function detect( string $xliffContent ): int { |
|
| 27 | - preg_match( '|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr( $xliffContent, 0, 1000 ), $versionMatches ); |
|
| 26 | + public static function detect(string $xliffContent): int { |
|
| 27 | + preg_match('|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr($xliffContent, 0, 1000), $versionMatches); |
|
| 28 | 28 | |
| 29 | - if ( empty( $versionMatches ) ) { |
|
| 30 | - throw new NotValidFileException( 'This is not a valid xliff file' ); |
|
| 29 | + if (empty($versionMatches)) { |
|
| 30 | + throw new NotValidFileException('This is not a valid xliff file'); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - $version = $versionMatches[ 1 ]; |
|
| 33 | + $version = $versionMatches[1]; |
|
| 34 | 34 | |
| 35 | - return self::resolveVersion( $version ); |
|
| 35 | + return self::resolveVersion($version); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,15 +41,15 @@ discard block |
||
| 41 | 41 | * @return int |
| 42 | 42 | * @throws NotSupportedVersionException |
| 43 | 43 | */ |
| 44 | - private static function resolveVersion( string $version ): int { |
|
| 45 | - if ( in_array( $version, self::$versions_1 ) ) { |
|
| 44 | + private static function resolveVersion(string $version): int { |
|
| 45 | + if (in_array($version, self::$versions_1)) { |
|
| 46 | 46 | return 1; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ( in_array( $version, self::$versions_2 ) ) { |
|
| 49 | + if (in_array($version, self::$versions_2)) { |
|
| 50 | 50 | return 2; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - throw new NotSupportedVersionException( 'Not supported version' ); |
|
| 53 | + throw new NotSupportedVersionException('Not supported version'); |
|
| 54 | 54 | } |
| 55 | 55 | } |
@@ -28,14 +28,14 @@ |
||
| 28 | 28 | ?LoggerInterface $logger = null, |
| 29 | 29 | ?XliffReplacerCallbackInterface $callback = null |
| 30 | 30 | ): AbstractXliffReplacer { |
| 31 | - $info = XliffProprietaryDetect::getInfo( $originalXliffPath ); |
|
| 31 | + $info = XliffProprietaryDetect::getInfo($originalXliffPath); |
|
| 32 | 32 | |
| 33 | - if ( $info[ 'version' ] == 1 && $info[ 'proprietary_short_name' ] !== 'trados' ) { |
|
| 34 | - return new Xliff12( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
| 35 | - } elseif ( $info[ 'version' ] == 2 ) { |
|
| 36 | - return new Xliff20( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
| 33 | + if ($info['version'] == 1 && $info['proprietary_short_name'] !== 'trados') { |
|
| 34 | + return new Xliff12($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
| 35 | + } elseif ($info['version'] == 2) { |
|
| 36 | + return new Xliff20($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - return new XliffSdl( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
| 39 | + return new XliffSdl($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
| 40 | 40 | } |
| 41 | 41 | } |
@@ -16,24 +16,24 @@ discard block |
||
| 16 | 16 | /** |
| 17 | 17 | * @inheritDoc |
| 18 | 18 | */ |
| 19 | - protected function tagOpen( $parser, string $name, array $attr ) { |
|
| 19 | + protected function tagOpen($parser, string $name, array $attr) { |
|
| 20 | 20 | |
| 21 | - $this->handleOpenUnit( $name, $attr ); |
|
| 21 | + $this->handleOpenUnit($name, $attr); |
|
| 22 | 22 | |
| 23 | 23 | // check if we are entering into a <target> |
| 24 | - $this->checkSetInTarget( $name ); |
|
| 24 | + $this->checkSetInTarget($name); |
|
| 25 | 25 | |
| 26 | 26 | // reset Marker positions |
| 27 | - if ( 'sdl:seg-defs' == $name ) { |
|
| 27 | + if ('sdl:seg-defs' == $name) { |
|
| 28 | 28 | $this->segmentInUnitPosition = 0; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // open buffer |
| 32 | - $this->setInBuffer( $name ); |
|
| 32 | + $this->setInBuffer($name); |
|
| 33 | 33 | |
| 34 | 34 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
| 35 | 35 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
| 36 | - if ( !$this->inTarget ) { |
|
| 36 | + if (!$this->inTarget) { |
|
| 37 | 37 | |
| 38 | 38 | // costruct tag |
| 39 | 39 | $tag = "<$name "; |
@@ -43,16 +43,16 @@ discard block |
||
| 43 | 43 | // so the check on it's name is not enough |
| 44 | 44 | $_sdlStatus_confWritten = false; |
| 45 | 45 | |
| 46 | - foreach ( $attr as $k => $v ) { |
|
| 46 | + foreach ($attr as $k => $v) { |
|
| 47 | 47 | |
| 48 | 48 | // if tag name is file, we must replace the target-language attribute |
| 49 | - if ( $name == 'file' && $k == 'target-language' && !empty( $this->targetLang ) ) { |
|
| 49 | + if ($name == 'file' && $k == 'target-language' && !empty($this->targetLang)) { |
|
| 50 | 50 | //replace Target language with job language provided from constructor |
| 51 | 51 | $tag .= "$k=\"$this->targetLang\" "; |
| 52 | 52 | } else { |
| 53 | 53 | //normal tag flux, put attributes in it |
| 54 | 54 | // Warning, this is NOT an elseif |
| 55 | - if ( $k != 'conf' ) { |
|
| 55 | + if ($k != 'conf') { |
|
| 56 | 56 | //put also the current attribute in it if it is not a "conf" attribute |
| 57 | 57 | $tag .= "$k=\"$v\" "; |
| 58 | 58 | } |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | $seg = $this->getCurrentSegment(); |
| 63 | 63 | |
| 64 | - if ( 'sdl:seg' == $name && !empty( $seg ) and isset( $seg[ 'sid' ] ) ) { |
|
| 65 | - $tag .= $this->prepareTargetStatuses( $seg ); |
|
| 64 | + if ('sdl:seg' == $name && !empty($seg) and isset($seg['sid'])) { |
|
| 65 | + $tag .= $this->prepareTargetStatuses($seg); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
|
| 68 | + $this->checkForSelfClosedTagAndFlush($parser, $tag); |
|
| 69 | 69 | |
| 70 | 70 | } |
| 71 | 71 | |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | - protected function prepareTargetStatuses( $segment ): string { |
|
| 79 | + protected function prepareTargetStatuses($segment): string { |
|
| 80 | 80 | $statusMap = [ |
| 81 | 81 | 'NEW' => '', |
| 82 | 82 | 'DRAFT' => 'Draft', |
@@ -86,19 +86,19 @@ discard block |
||
| 86 | 86 | 'REJECTED' => 'RejectedTranslation', |
| 87 | 87 | ]; |
| 88 | 88 | |
| 89 | - return "conf=\"{$statusMap[ $segment[ 'status' ] ]}\" "; |
|
| 89 | + return "conf=\"{$statusMap[$segment['status']]}\" "; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - protected function rebuildMarks( array $seg, string $translation ): string { |
|
| 92 | + protected function rebuildMarks(array $seg, string $translation): string { |
|
| 93 | 93 | |
| 94 | - $trailingSpaces = str_repeat( ' ', Strings::getTheNumberOfTrailingSpaces( $translation ) ); |
|
| 94 | + $trailingSpaces = str_repeat(' ', Strings::getTheNumberOfTrailingSpaces($translation)); |
|
| 95 | 95 | |
| 96 | - if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
|
| 97 | - if ( $this->targetLang === 'ja-JP' ) { |
|
| 98 | - $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] ); |
|
| 96 | + if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') { |
|
| 97 | + if ($this->targetLang === 'ja-JP') { |
|
| 98 | + $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . rtrim( $translation ) . $seg[ 'mrk_succ_tags' ] . "</mrk>" . $trailingSpaces; |
|
| 101 | + $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . rtrim($translation) . $seg['mrk_succ_tags'] . "</mrk>" . $trailingSpaces; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | return $translation; |
@@ -12,5 +12,5 @@ |
||
| 12 | 12 | * |
| 13 | 13 | * @return bool |
| 14 | 14 | */ |
| 15 | - public function thereAreErrors( int $segmentId, string $segment, string $translation, ?array $dataRefMap = [], ?string $error = null ): bool; |
|
| 15 | + public function thereAreErrors(int $segmentId, string $segment, string $translation, ?array $dataRefMap = [], ?string $error = null): bool; |
|
| 16 | 16 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | ?string $lastMrkState = null |
| 27 | 27 | ): array { |
| 28 | 28 | |
| 29 | - $status = empty( $status ) ? TranslationStatus::STATUS_TRANSLATED : $status; |
|
| 29 | + $status = empty($status) ? TranslationStatus::STATUS_TRANSLATED : $status; |
|
| 30 | 30 | |
| 31 | 31 | $stateLevelsMap = [ |
| 32 | 32 | TranslationStatus::STATUS_APPROVED2 => 100, |
@@ -37,26 +37,26 @@ discard block |
||
| 37 | 37 | TranslationStatus::STATUS_NEW => 50 |
| 38 | 38 | ]; |
| 39 | 39 | |
| 40 | - $orderedValues = array_flip( $stateLevelsMap ); |
|
| 40 | + $orderedValues = array_flip($stateLevelsMap); |
|
| 41 | 41 | |
| 42 | 42 | // Define state mappings for different statuses |
| 43 | 43 | $stateMap = [ |
| 44 | - TranslationStatus::STATUS_APPROVED2 => [ "state=\"final\"", TranslationStatus::STATUS_APPROVED2 ], |
|
| 44 | + TranslationStatus::STATUS_APPROVED2 => ["state=\"final\"", TranslationStatus::STATUS_APPROVED2], |
|
| 45 | 45 | TranslationStatus::STATUS_APPROVED => [ |
| 46 | - ( $xliffVersion === 2 ) ? "state=\"reviewed\"" : "state=\"signed-off\"", |
|
| 46 | + ($xliffVersion === 2) ? "state=\"reviewed\"" : "state=\"signed-off\"", |
|
| 47 | 47 | TranslationStatus::STATUS_APPROVED |
| 48 | 48 | ], |
| 49 | - TranslationStatus::STATUS_TRANSLATED => [ "state=\"translated\"", TranslationStatus::STATUS_TRANSLATED ], |
|
| 49 | + TranslationStatus::STATUS_TRANSLATED => ["state=\"translated\"", TranslationStatus::STATUS_TRANSLATED], |
|
| 50 | 50 | TranslationStatus::STATUS_REJECTED => [ |
| 51 | - ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"needs-review-translation\"", |
|
| 51 | + ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"needs-review-translation\"", |
|
| 52 | 52 | TranslationStatus::STATUS_REJECTED |
| 53 | 53 | ], |
| 54 | 54 | TranslationStatus::STATUS_NEW => [ |
| 55 | - ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\"", |
|
| 55 | + ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\"", |
|
| 56 | 56 | TranslationStatus::STATUS_NEW |
| 57 | 57 | ], |
| 58 | 58 | TranslationStatus::STATUS_DRAFT => [ |
| 59 | - ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\"", |
|
| 59 | + ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\"", |
|
| 60 | 60 | TranslationStatus::STATUS_DRAFT |
| 61 | 61 | ], |
| 62 | 62 | ]; |
@@ -67,14 +67,14 @@ discard block |
||
| 67 | 67 | // ---> $seg[ 'status' ] is NULL |
| 68 | 68 | // If lastMrkState is empty |
| 69 | 69 | $minStatus = min( |
| 70 | - $stateLevelsMap[ $status ], |
|
| 71 | - ( $stateLevelsMap[ $lastMrkState ] ?? $stateLevelsMap[ TranslationStatus::STATUS_NEW ] ) |
|
| 70 | + $stateLevelsMap[$status], |
|
| 71 | + ($stateLevelsMap[$lastMrkState] ?? $stateLevelsMap[TranslationStatus::STATUS_NEW]) |
|
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | 74 | // If the last mark state is set, get the minimum value, otherwise get the current state |
| 75 | - [ $state_prop, $lastMrkState ] = empty( $lastMrkState ) ? $stateMap[ $status ] : $stateMap[ $orderedValues[ $minStatus ] ]; |
|
| 75 | + [$state_prop, $lastMrkState] = empty($lastMrkState) ? $stateMap[$status] : $stateMap[$orderedValues[$minStatus]]; |
|
| 76 | 76 | |
| 77 | - return [ $state_prop, $lastMrkState ]; |
|
| 77 | + return [$state_prop, $lastMrkState]; |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | |
@@ -27,28 +27,28 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @inheritDoc |
| 29 | 29 | */ |
| 30 | - protected function tagOpen( $parser, string $name, array $attr ) { |
|
| 30 | + protected function tagOpen($parser, string $name, array $attr) { |
|
| 31 | 31 | |
| 32 | - $this->handleOpenUnit( $name, $attr ); |
|
| 32 | + $this->handleOpenUnit($name, $attr); |
|
| 33 | 33 | |
| 34 | - $this->checkSetInTarget( $name ); |
|
| 34 | + $this->checkSetInTarget($name); |
|
| 35 | 35 | |
| 36 | 36 | // open buffer |
| 37 | - $this->setInBuffer( $name ); |
|
| 37 | + $this->setInBuffer($name); |
|
| 38 | 38 | |
| 39 | 39 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
| 40 | 40 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
| 41 | - if ( !$this->inTarget ) { |
|
| 41 | + if (!$this->inTarget) { |
|
| 42 | 42 | |
| 43 | 43 | $tag = ''; |
| 44 | 44 | |
| 45 | 45 | // construct tag |
| 46 | 46 | $tag .= "<$name "; |
| 47 | 47 | |
| 48 | - foreach ( $attr as $k => $v ) { |
|
| 48 | + foreach ($attr as $k => $v) { |
|
| 49 | 49 | |
| 50 | 50 | //if tag name is file, we must replace the target-language attribute |
| 51 | - if ( $name === 'file' && $k === 'target-language' && !empty( $this->targetLang ) ) { |
|
| 51 | + if ($name === 'file' && $k === 'target-language' && !empty($this->targetLang)) { |
|
| 52 | 52 | //replace Target language with job language provided from constructor |
| 53 | 53 | $tag .= "$k=\"$this->targetLang\" "; |
| 54 | 54 | } else { |
@@ -59,20 +59,20 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $seg = $this->getCurrentSegment(); |
| 61 | 61 | |
| 62 | - if ( $name === $this->tuTagName && !empty( $seg ) and isset( $seg[ 'sid' ] ) ) { |
|
| 62 | + if ($name === $this->tuTagName && !empty($seg) and isset($seg['sid'])) { |
|
| 63 | 63 | |
| 64 | 64 | // add `help-id` to xliff v.1* |
| 65 | - if ( strpos( $tag, 'help-id' ) === false ) { |
|
| 66 | - if ( !empty( $seg[ 'sid' ] ) ) { |
|
| 67 | - $tag .= "help-id=\"{$seg[ 'sid' ]}\" "; |
|
| 65 | + if (strpos($tag, 'help-id') === false) { |
|
| 66 | + if (!empty($seg['sid'])) { |
|
| 67 | + $tag .= "help-id=\"{$seg['sid']}\" "; |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - $tag = $this->handleOpenXliffTag( $name, $attr, $tag ); |
|
| 73 | + $tag = $this->handleOpenXliffTag($name, $attr, $tag); |
|
| 74 | 74 | |
| 75 | - $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
|
| 75 | + $this->checkForSelfClosedTagAndFlush($parser, $tag); |
|
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | /** |
| 83 | 83 | * @inheritDoc |
| 84 | 84 | */ |
| 85 | - protected function tagClose( $parser, string $name ) { |
|
| 85 | + protected function tagClose($parser, string $name) { |
|
| 86 | 86 | $tag = ''; |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,15 +91,15 @@ discard block |
||
| 91 | 91 | * |
| 92 | 92 | * self::tagOpen method |
| 93 | 93 | */ |
| 94 | - if ( !$this->isEmpty ) { |
|
| 94 | + if (!$this->isEmpty) { |
|
| 95 | 95 | |
| 96 | - if ( !$this->inTarget ) { |
|
| 96 | + if (!$this->inTarget) { |
|
| 97 | 97 | $tag = "</$name>"; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if ( 'target' == $name ) { |
|
| 100 | + if ('target' == $name) { |
|
| 101 | 101 | |
| 102 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
| 102 | + if (isset($this->transUnits[$this->currentTransUnitId])) { |
|
| 103 | 103 | |
| 104 | 104 | // get translation of current segment, by indirect indexing: id -> positional index -> segment |
| 105 | 105 | // actually there may be more than one segment to that ID if there are two mrk of the same source segment |
@@ -110,42 +110,42 @@ discard block |
||
| 110 | 110 | $this->targetWasWritten = true; |
| 111 | 111 | // signal we are leaving a target |
| 112 | 112 | $this->inTarget = false; |
| 113 | - $this->postProcAndFlush( $this->outputFP, $tag, true ); |
|
| 113 | + $this->postProcAndFlush($this->outputFP, $tag, true); |
|
| 114 | 114 | |
| 115 | - } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
|
| 115 | + } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section |
|
| 116 | 116 | |
| 117 | 117 | $this->bufferIsActive = false; |
| 118 | 118 | $tag = $this->CDATABuffer . "</$name>"; |
| 119 | 119 | $this->CDATABuffer = ""; |
| 120 | 120 | |
| 121 | 121 | //flush to the pointer |
| 122 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 122 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 123 | 123 | |
| 124 | - } elseif ( $name === $this->tuTagName ) { |
|
| 124 | + } elseif ($name === $this->tuTagName) { |
|
| 125 | 125 | |
| 126 | 126 | $tag = ""; |
| 127 | 127 | |
| 128 | 128 | // handling </trans-unit> closure |
| 129 | - if ( !$this->targetWasWritten ) { |
|
| 129 | + if (!$this->targetWasWritten) { |
|
| 130 | 130 | |
| 131 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
| 131 | + if (isset($this->transUnits[$this->currentTransUnitId])) { |
|
| 132 | 132 | $tag = $this->rebuildTarget(); |
| 133 | 133 | } else { |
| 134 | - $tag = $this->createTargetTag( "", "" ); |
|
| 134 | + $tag = $this->createTargetTag("", ""); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $tag .= "</$this->tuTagName>"; |
|
| 139 | + $tag .= "</$this->tuTagName>"; |
|
| 140 | 140 | $this->targetWasWritten = false; |
| 141 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 141 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 142 | 142 | |
| 143 | - } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
| 143 | + } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
| 144 | 144 | $this->CDATABuffer .= "</$name>"; |
| 145 | 145 | // Do NOT Flush |
| 146 | 146 | } else { //generic tag closure do Nothing |
| 147 | 147 | // flush to pointer |
| 148 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 148 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | } else { |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
| 157 | - if ( $this->tuTagName === $name ) { |
|
| 157 | + if ($this->tuTagName === $name) { |
|
| 158 | 158 | $this->currentTransUnitIsTranslatable = null; |
| 159 | 159 | $this->inTU = false; |
| 160 | 160 | $this->hasWrittenCounts = false; |
@@ -171,31 +171,31 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | - protected function prepareTranslation( array $seg, string $transUnitTranslation = "" ): string { |
|
| 174 | + protected function prepareTranslation(array $seg, string $transUnitTranslation = ""): string { |
|
| 175 | 175 | |
| 176 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
| 177 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
| 176 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
| 177 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
| 178 | 178 | |
| 179 | - if ( $seg [ 'translation' ] == '' ) { |
|
| 179 | + if ($seg ['translation'] == '') { |
|
| 180 | 180 | $translation = $segment; |
| 181 | 181 | } else { |
| 182 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
| 183 | - $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null; |
|
| 184 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, [], $error ) ) { |
|
| 182 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
| 183 | + $error = (!empty($seg['error'])) ? $seg['error'] : null; |
|
| 184 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, [], $error)) { |
|
| 185 | 185 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
| 186 | 186 | } |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $transUnitTranslation .= $seg[ 'prev_tags' ] . $this->rebuildMarks( $seg, $translation ) . ltrim( $seg[ 'succ_tags' ] ); |
|
| 190 | + $transUnitTranslation .= $seg['prev_tags'] . $this->rebuildMarks($seg, $translation) . ltrim($seg['succ_tags']); |
|
| 191 | 191 | |
| 192 | 192 | return $transUnitTranslation; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - protected function rebuildMarks( array $seg, string $translation ): string { |
|
| 195 | + protected function rebuildMarks(array $seg, string $translation): string { |
|
| 196 | 196 | |
| 197 | - if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
|
| 198 | - $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>"; |
|
| 197 | + if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') { |
|
| 198 | + $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>"; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | return $translation; |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | * |
| 211 | 211 | * @return string |
| 212 | 212 | */ |
| 213 | - private function createTargetTag( string $translation, string $stateProp ): string { |
|
| 213 | + private function createTargetTag(string $translation, string $stateProp): string { |
|
| 214 | 214 | $targetLang = ' xml:lang="' . $this->targetLang . '"'; |
| 215 | 215 | $tag = "<target $targetLang $stateProp>$translation</target>"; |
| 216 | - $tag .= "\n<count-group name=\"$this->currentTransUnitId\"><count count-type=\"x-matecat-raw\">" . $this->counts[ 'raw_word_count' ] . "</count><count count-type=\"x-matecat-weighted\">" . $this->counts[ 'eq_word_count' ] . '</count></count-group>'; |
|
| 216 | + $tag .= "\n<count-group name=\"$this->currentTransUnitId\"><count count-type=\"x-matecat-raw\">" . $this->counts['raw_word_count'] . "</count><count count-type=\"x-matecat-weighted\">" . $this->counts['eq_word_count'] . '</count></count-group>'; |
|
| 217 | 217 | |
| 218 | 218 | return $tag; |
| 219 | 219 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | // we must reset the lastMrkId found because this is a new segment. |
| 230 | 230 | $lastMrkId = -1; |
| 231 | 231 | |
| 232 | - foreach ( $this->lastTransUnit as $pos => $seg ) { |
|
| 232 | + foreach ($this->lastTransUnit as $pos => $seg) { |
|
| 233 | 233 | |
| 234 | 234 | /* |
| 235 | 235 | * This routine works to respect the positional orders of markers. |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | * pre-assign zero to the new mrk if this is the first one ( in this segment ) |
| 243 | 243 | * If it is null leave it NULL |
| 244 | 244 | */ |
| 245 | - if ( (int)$seg[ "mrk_id" ] < 0 && $seg[ "mrk_id" ] !== null ) { |
|
| 246 | - $seg[ "mrk_id" ] = 0; |
|
| 245 | + if ((int)$seg["mrk_id"] < 0 && $seg["mrk_id"] !== null) { |
|
| 246 | + $seg["mrk_id"] = 0; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /* |
@@ -252,33 +252,33 @@ discard block |
||
| 252 | 252 | * ( null <= -1 ) === true |
| 253 | 253 | * so, cast to int |
| 254 | 254 | */ |
| 255 | - if ( (int)$seg[ "mrk_id" ] <= $lastMrkId ) { |
|
| 255 | + if ((int)$seg["mrk_id"] <= $lastMrkId) { |
|
| 256 | 256 | break; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // update counts |
| 260 | - if ( !empty( $seg ) ) { |
|
| 261 | - $this->updateSegmentCounts( $seg ); |
|
| 260 | + if (!empty($seg)) { |
|
| 261 | + $this->updateSegmentCounts($seg); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // delete translations so the prepareSegment |
| 265 | 265 | // will put source content in target tag |
| 266 | - if ( $this->sourceInTarget ) { |
|
| 267 | - $seg[ 'translation' ] = ''; |
|
| 266 | + if ($this->sourceInTarget) { |
|
| 267 | + $seg['translation'] = ''; |
|
| 268 | 268 | $this->resetCounts(); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | // append $translation |
| 272 | - $translation = $this->prepareTranslation( $seg, $translation ); |
|
| 272 | + $translation = $this->prepareTranslation($seg, $translation); |
|
| 273 | 273 | |
| 274 | - $lastMrkId = $seg[ "mrk_id" ]; |
|
| 274 | + $lastMrkId = $seg["mrk_id"]; |
|
| 275 | 275 | |
| 276 | - [ $stateProp, $lastMrkState ] = StatusToStateAttribute::getState( $this->xliffVersion, $seg[ 'status' ], $lastMrkState ); |
|
| 276 | + [$stateProp, $lastMrkState] = StatusToStateAttribute::getState($this->xliffVersion, $seg['status'], $lastMrkState); |
|
| 277 | 277 | |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | //append translation |
| 281 | - return $this->createTargetTag( $translation, $stateProp ); |
|
| 281 | + return $this->createTargetTag($translation, $stateProp); |
|
| 282 | 282 | |
| 283 | 283 | } |
| 284 | 284 | |