@@ -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 | } |
@@ -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 | } |
@@ -22,11 +22,11 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | - public static function getInfoFromXliffContent( string $xliffContent ): array { |
|
| 25 | + public static function getInfoFromXliffContent(string $xliffContent): array { |
|
| 26 | 26 | self::reset(); |
| 27 | - $tmp = self::getFirst1024CharsFromXliff( $xliffContent ); |
|
| 27 | + $tmp = self::getFirst1024CharsFromXliff($xliffContent); |
|
| 28 | 28 | |
| 29 | - return self::getInfoFromTmp( $tmp ); |
|
| 29 | + return self::getInfoFromTmp($tmp); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @return array |
| 36 | 36 | */ |
| 37 | - public static function getInfo( string $fullPathToFile ): array { |
|
| 37 | + public static function getInfo(string $fullPathToFile): array { |
|
| 38 | 38 | self::reset(); |
| 39 | - $tmp = self::getFirst1024CharsFromXliff( null, $fullPathToFile ); |
|
| 40 | - self::$fileType[ 'info' ] = Files::pathInfo( $fullPathToFile ); |
|
| 39 | + $tmp = self::getFirst1024CharsFromXliff(null, $fullPathToFile); |
|
| 40 | + self::$fileType['info'] = Files::pathInfo($fullPathToFile); |
|
| 41 | 41 | |
| 42 | - return self::getInfoFromTmp( $tmp ); |
|
| 42 | + return self::getInfoFromTmp($tmp); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -47,21 +47,21 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return array |
| 49 | 49 | */ |
| 50 | - private static function getInfoFromTmp( array $tmp ): array { |
|
| 50 | + private static function getInfoFromTmp(array $tmp): array { |
|
| 51 | 51 | try { |
| 52 | - self::checkVersion( $tmp ); |
|
| 53 | - } catch ( Exception $ignore ) { |
|
| 52 | + self::checkVersion($tmp); |
|
| 53 | + } catch (Exception $ignore) { |
|
| 54 | 54 | // do nothing |
| 55 | 55 | // self::$fileType[ 'version' ] is left empty |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // run CheckXliffProprietaryPipeline |
| 59 | - $pipeline = self::runPipeline( $tmp ); |
|
| 59 | + $pipeline = self::runPipeline($tmp); |
|
| 60 | 60 | |
| 61 | - self::$fileType[ 'proprietary' ] = $pipeline[ 'proprietary' ]; |
|
| 62 | - self::$fileType[ 'proprietary_name' ] = $pipeline[ 'proprietary_name' ]; |
|
| 63 | - self::$fileType[ 'proprietary_short_name' ] = $pipeline[ 'proprietary_short_name' ]; |
|
| 64 | - self::$fileType[ 'converter_version' ] = $pipeline[ 'converter_version' ]; |
|
| 61 | + self::$fileType['proprietary'] = $pipeline['proprietary']; |
|
| 62 | + self::$fileType['proprietary_name'] = $pipeline['proprietary_name']; |
|
| 63 | + self::$fileType['proprietary_short_name'] = $pipeline['proprietary_short_name']; |
|
| 64 | + self::$fileType['converter_version'] = $pipeline['converter_version']; |
|
| 65 | 65 | |
| 66 | 66 | return self::$fileType; |
| 67 | 67 | } |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return array |
| 73 | 73 | */ |
| 74 | - private static function runPipeline( ?array $tmp = [] ): array { |
|
| 75 | - $pipeline = new CheckXliffProprietaryPipeline( $tmp ); |
|
| 76 | - $pipeline->addCheck( new CheckSDL() ); |
|
| 77 | - $pipeline->addCheck( new CheckGlobalSight() ); |
|
| 78 | - $pipeline->addCheck( new CheckMateCATConverter() ); |
|
| 79 | - $pipeline->addCheck( new CheckXliffVersion2() ); |
|
| 74 | + private static function runPipeline(?array $tmp = []): array { |
|
| 75 | + $pipeline = new CheckXliffProprietaryPipeline($tmp); |
|
| 76 | + $pipeline->addCheck(new CheckSDL()); |
|
| 77 | + $pipeline->addCheck(new CheckGlobalSight()); |
|
| 78 | + $pipeline->addCheck(new CheckMateCATConverter()); |
|
| 79 | + $pipeline->addCheck(new CheckXliffVersion2()); |
|
| 80 | 80 | |
| 81 | 81 | return $pipeline->run(); |
| 82 | 82 | } |
@@ -98,9 +98,9 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @return string |
| 100 | 100 | */ |
| 101 | - private static function getFirst1024CharsFromString( ?string $stringData ): string { |
|
| 102 | - if ( !empty( $stringData ) ) { |
|
| 103 | - return substr( $stringData, 0, 1024 ); |
|
| 101 | + private static function getFirst1024CharsFromString(?string $stringData): string { |
|
| 102 | + if (!empty($stringData)) { |
|
| 103 | + return substr($stringData, 0, 1024); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | return ''; |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return string |
| 113 | 113 | */ |
| 114 | - private static function getFirst1024CharsFromFile( ?string $fullPathToFile ): string { |
|
| 114 | + private static function getFirst1024CharsFromFile(?string $fullPathToFile): string { |
|
| 115 | 115 | $stringData = ''; |
| 116 | - if ( !empty( $fullPathToFile ) && is_file( $fullPathToFile ) ) { |
|
| 117 | - $file_pointer = fopen( "$fullPathToFile", 'r' ); |
|
| 116 | + if (!empty($fullPathToFile) && is_file($fullPathToFile)) { |
|
| 117 | + $file_pointer = fopen("$fullPathToFile", 'r'); |
|
| 118 | 118 | // Checking Requirements (By specs, I know that xliff version is in the first 1KB) |
| 119 | - $stringData = fread( $file_pointer, 1024 ); |
|
| 120 | - fclose( $file_pointer ); |
|
| 119 | + $stringData = fread($file_pointer, 1024); |
|
| 120 | + fclose($file_pointer); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return $stringData; |
@@ -130,13 +130,13 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @return string[] |
| 132 | 132 | */ |
| 133 | - private static function getFirst1024CharsFromXliff( ?string $stringData = null, string $fullPathToFile = null ): ?array { |
|
| 134 | - $stringData = static::getFirst1024CharsFromString( $stringData ); |
|
| 135 | - if ( empty( $stringData ) ) { |
|
| 136 | - $stringData = static::getFirst1024CharsFromFile( $fullPathToFile ); |
|
| 133 | + private static function getFirst1024CharsFromXliff(?string $stringData = null, string $fullPathToFile = null): ?array { |
|
| 134 | + $stringData = static::getFirst1024CharsFromString($stringData); |
|
| 135 | + if (empty($stringData)) { |
|
| 136 | + $stringData = static::getFirst1024CharsFromFile($fullPathToFile); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - return !empty( $stringData ) ? [ $stringData ] : []; |
|
| 139 | + return !empty($stringData) ? [$stringData] : []; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | * @throws NotSupportedVersionException |
| 146 | 146 | * @throws NotValidFileException |
| 147 | 147 | */ |
| 148 | - protected static function checkVersion( array $tmp ) { |
|
| 149 | - if ( isset( $tmp[ 0 ] ) ) { |
|
| 150 | - self::$fileType[ 'version' ] = XliffVersionDetector::detect( $tmp[ 0 ] ); |
|
| 148 | + protected static function checkVersion(array $tmp) { |
|
| 149 | + if (isset($tmp[0])) { |
|
| 150 | + self::$fileType['version'] = XliffVersionDetector::detect($tmp[0]); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | * @throws NotSupportedVersionException |
| 159 | 159 | * @throws NotValidFileException |
| 160 | 160 | */ |
| 161 | - public static function getInfoByStringData( string $stringData ): array { |
|
| 161 | + public static function getInfoByStringData(string $stringData): array { |
|
| 162 | 162 | self::reset(); |
| 163 | 163 | |
| 164 | - $tmp = self::getFirst1024CharsFromXliff( $stringData ); |
|
| 165 | - self::$fileType[ 'info' ] = []; |
|
| 166 | - self::checkVersion( $tmp ); |
|
| 164 | + $tmp = self::getFirst1024CharsFromXliff($stringData); |
|
| 165 | + self::$fileType['info'] = []; |
|
| 166 | + self::checkVersion($tmp); |
|
| 167 | 167 | |
| 168 | 168 | // run CheckXliffProprietaryPipeline |
| 169 | - $pipeline = self::runPipeline( $tmp ); |
|
| 169 | + $pipeline = self::runPipeline($tmp); |
|
| 170 | 170 | |
| 171 | - self::$fileType[ 'proprietary' ] = $pipeline[ 'proprietary' ]; |
|
| 172 | - self::$fileType[ 'proprietary_name' ] = $pipeline[ 'proprietary_name' ]; |
|
| 173 | - self::$fileType[ 'proprietary_short_name' ] = $pipeline[ 'proprietary_short_name' ]; |
|
| 174 | - self::$fileType[ 'converter_version' ] = $pipeline[ 'converter_version' ]; |
|
| 171 | + self::$fileType['proprietary'] = $pipeline['proprietary']; |
|
| 172 | + self::$fileType['proprietary_name'] = $pipeline['proprietary_name']; |
|
| 173 | + self::$fileType['proprietary_short_name'] = $pipeline['proprietary_short_name']; |
|
| 174 | + self::$fileType['converter_version'] = $pipeline['converter_version']; |
|
| 175 | 175 | |
| 176 | 176 | return self::$fileType; |
| 177 | 177 | } |
@@ -183,33 +183,33 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @return bool|int |
| 185 | 185 | */ |
| 186 | - public static function fileMustBeConverted( string $fullPath, bool $enforceOnXliff = false, ?string $filterAddress = null ) { |
|
| 186 | + public static function fileMustBeConverted(string $fullPath, bool $enforceOnXliff = false, ?string $filterAddress = null) { |
|
| 187 | 187 | $convert = true; |
| 188 | 188 | |
| 189 | - $fileType = self::getInfo( $fullPath ); |
|
| 190 | - $memoryFileType = Files::getMemoryFileType( $fullPath ); |
|
| 189 | + $fileType = self::getInfo($fullPath); |
|
| 190 | + $memoryFileType = Files::getMemoryFileType($fullPath); |
|
| 191 | 191 | |
| 192 | - if ( Files::isXliff( $fullPath ) || $memoryFileType ) { |
|
| 193 | - if ( !empty( $filterAddress ) ) { |
|
| 192 | + if (Files::isXliff($fullPath) || $memoryFileType) { |
|
| 193 | + if (!empty($filterAddress)) { |
|
| 194 | 194 | |
| 195 | 195 | //conversion enforce |
| 196 | - if ( !$enforceOnXliff ) { |
|
| 196 | + if (!$enforceOnXliff) { |
|
| 197 | 197 | |
| 198 | 198 | //if file is not proprietary AND Enforce is disabled |
| 199 | 199 | //we take it as is |
| 200 | - if ( !$fileType[ 'proprietary' ] || $memoryFileType ) { |
|
| 200 | + if (!$fileType['proprietary'] || $memoryFileType) { |
|
| 201 | 201 | $convert = false; |
| 202 | 202 | //ok don't convert a standard sdlxliff |
| 203 | 203 | } |
| 204 | 204 | } else { |
| 205 | 205 | //if conversion enforce is active |
| 206 | 206 | //we force all xliff files but not files produced by SDL Studio because we can handle them |
| 207 | - if ( in_array( $fileType[ 'proprietary_short_name' ], [ 'matecat_converter', 'trados', 'xliff_v2' ] ) || $memoryFileType ) { |
|
| 207 | + if (in_array($fileType['proprietary_short_name'], ['matecat_converter', 'trados', 'xliff_v2']) || $memoryFileType) { |
|
| 208 | 208 | $convert = false; |
| 209 | 209 | //ok don't convert a standard sdlxliff |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | - } elseif ( $fileType[ 'proprietary' ] ) { |
|
| 212 | + } elseif ($fileType['proprietary']) { |
|
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | 215 | * Application misconfiguration. |
@@ -18,15 +18,15 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return array|mixed |
| 20 | 20 | */ |
| 21 | - public static function pathInfo( string $path, ?int $options = 15 ) { |
|
| 22 | - $rawPath = explode( DIRECTORY_SEPARATOR, $path ); |
|
| 21 | + public static function pathInfo(string $path, ?int $options = 15) { |
|
| 22 | + $rawPath = explode(DIRECTORY_SEPARATOR, $path); |
|
| 23 | 23 | |
| 24 | - $basename = array_pop( $rawPath ); |
|
| 25 | - $dirname = implode( DIRECTORY_SEPARATOR, $rawPath ); |
|
| 24 | + $basename = array_pop($rawPath); |
|
| 25 | + $dirname = implode(DIRECTORY_SEPARATOR, $rawPath); |
|
| 26 | 26 | |
| 27 | - $explodedFileName = explode( ".", $basename ); |
|
| 28 | - $extension = strtolower( array_pop( $explodedFileName ) ); |
|
| 29 | - $filename = implode( ".", $explodedFileName ); |
|
| 27 | + $explodedFileName = explode(".", $basename); |
|
| 28 | + $extension = strtolower(array_pop($explodedFileName)); |
|
| 29 | + $filename = implode(".", $explodedFileName); |
|
| 30 | 30 | |
| 31 | 31 | $returnArray = []; |
| 32 | 32 | |
@@ -39,17 +39,17 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | // foreach flag, add in $return_array the corresponding field, |
| 41 | 41 | // obtained by variable name correspondence |
| 42 | - foreach ( $flagMap as $field => $i ) { |
|
| 42 | + foreach ($flagMap as $field => $i) { |
|
| 43 | 43 | //binary AND |
| 44 | - if ( ( $options & $i ) > 0 ) { |
|
| 44 | + if (($options & $i) > 0) { |
|
| 45 | 45 | //variable substitution: $field can be one between 'dirname', 'basename', 'extension', 'filename' |
| 46 | 46 | // $$field gets the value of the variable named $field |
| 47 | - $returnArray[ $field ] = $$field; |
|
| 47 | + $returnArray[$field] = $$field; |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if ( count( $returnArray ) == 1 ) { |
|
| 52 | - $returnArray = array_pop( $returnArray ); |
|
| 51 | + if (count($returnArray) == 1) { |
|
| 52 | + $returnArray = array_pop($returnArray); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return $returnArray; |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @return ?string |
| 62 | 62 | */ |
| 63 | - public static function getExtension( $path ): ?string { |
|
| 64 | - $pathInfo = self::pathInfo( $path ); |
|
| 63 | + public static function getExtension($path): ?string { |
|
| 64 | + $pathInfo = self::pathInfo($path); |
|
| 65 | 65 | |
| 66 | - if ( empty( $pathInfo ) ) { |
|
| 66 | + if (empty($pathInfo)) { |
|
| 67 | 67 | return null; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - return strtolower( $pathInfo[ 'extension' ] ); |
|
| 70 | + return strtolower($pathInfo['extension']); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return bool |
| 77 | 77 | */ |
| 78 | - public static function isXliff( ?string $path ): bool { |
|
| 79 | - $extension = self::getExtension( $path ); |
|
| 78 | + public static function isXliff(?string $path): bool { |
|
| 79 | + $extension = self::getExtension($path); |
|
| 80 | 80 | |
| 81 | - if ( !$extension ) { |
|
| 81 | + if (!$extension) { |
|
| 82 | 82 | return false; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - switch ( $extension ) { |
|
| 85 | + switch ($extension) { |
|
| 86 | 86 | case 'xliff': |
| 87 | 87 | case 'sdlxliff': |
| 88 | 88 | case 'tmx': |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @return bool|string |
| 100 | 100 | */ |
| 101 | - public static function getMemoryFileType( string $path ) { |
|
| 102 | - $pathInfo = self::pathInfo( $path ); |
|
| 101 | + public static function getMemoryFileType(string $path) { |
|
| 102 | + $pathInfo = self::pathInfo($path); |
|
| 103 | 103 | |
| 104 | - if ( empty( $pathInfo ) ) { |
|
| 104 | + if (empty($pathInfo)) { |
|
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - switch ( strtolower( $pathInfo[ 'extension' ] ) ) { |
|
| 108 | + switch (strtolower($pathInfo['extension'])) { |
|
| 109 | 109 | case 'tmx': |
| 110 | 110 | return 'tmx'; |
| 111 | 111 | default: |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return bool |
| 120 | 120 | */ |
| 121 | - public static function isTMXFile( $path ): bool { |
|
| 122 | - return self::getMemoryFileType( $path ) === 'tmx'; |
|
| 121 | + public static function isTMXFile($path): bool { |
|
| 122 | + return self::getMemoryFileType($path) === 'tmx'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @return bool |
| 129 | 129 | */ |
| 130 | - public static function isGlossaryFile( $path ): bool { |
|
| 131 | - return self::getMemoryFileType( $path ) === 'glossary'; // return false |
|
| 130 | + public static function isGlossaryFile($path): bool { |
|
| 131 | + return self::getMemoryFileType($path) === 'glossary'; // return false |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | /** |
| 21 | 21 | * @var bool |
| 22 | 22 | */ |
| 23 | - protected bool $unitContainsMda = false; // check if <unit> already contains a <mda:metadata> (forXliff v 2.*) |
|
| 23 | + protected bool $unitContainsMda = false; // check if <unit> already contains a <mda:metadata> (forXliff v 2.*) |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var string |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * @var string |
| 37 | 37 | */ |
| 38 | - protected string $namespace = "matecat"; // Custom namespace |
|
| 38 | + protected string $namespace = "matecat"; // Custom namespace |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * @var array |
@@ -51,23 +51,23 @@ discard block |
||
| 51 | 51 | /** |
| 52 | 52 | * @inheritDoc |
| 53 | 53 | */ |
| 54 | - protected function tagOpen( $parser, string $name, array $attr ) { |
|
| 54 | + protected function tagOpen($parser, string $name, array $attr) { |
|
| 55 | 55 | |
| 56 | - $this->handleOpenUnit( $name, $attr ); |
|
| 56 | + $this->handleOpenUnit($name, $attr); |
|
| 57 | 57 | |
| 58 | - if ( 'mda:metadata' === $name ) { |
|
| 58 | + if ('mda:metadata' === $name) { |
|
| 59 | 59 | $this->unitContainsMda = true; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $this->trySetAltTrans( $name );; |
|
| 63 | - $this->checkSetInTarget( $name ); |
|
| 62 | + $this->trySetAltTrans($name); ; |
|
| 63 | + $this->checkSetInTarget($name); |
|
| 64 | 64 | |
| 65 | 65 | // open buffer |
| 66 | - $this->setInBuffer( $name ); |
|
| 66 | + $this->setInBuffer($name); |
|
| 67 | 67 | |
| 68 | 68 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
| 69 | 69 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
| 70 | - if ( !$this->inTarget ) { |
|
| 70 | + if (!$this->inTarget) { |
|
| 71 | 71 | |
| 72 | 72 | $tag = ''; |
| 73 | 73 | |
@@ -89,48 +89,48 @@ discard block |
||
| 89 | 89 | // |
| 90 | 90 | // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit |
| 91 | 91 | // |
| 92 | - if ( in_array( $name, [ 'notes', 'originalData', 'segment', 'ignorable' ] ) && |
|
| 92 | + if (in_array($name, ['notes', 'originalData', 'segment', 'ignorable']) && |
|
| 93 | 93 | $this->unitContainsMda === false && |
| 94 | - !empty( $this->transUnits[ $this->currentTransUnitId ] ) && |
|
| 94 | + !empty($this->transUnits[$this->currentTransUnitId]) && |
|
| 95 | 95 | !$this->hasWrittenCounts |
| 96 | 96 | ) { |
| 97 | 97 | // we need to update counts here |
| 98 | 98 | $this->updateCounts(); |
| 99 | 99 | $this->hasWrittenCounts = true; |
| 100 | - $tag .= $this->getWordCountGroupForXliffV2(); |
|
| 100 | + $tag .= $this->getWordCountGroupForXliffV2(); |
|
| 101 | 101 | $this->unitContainsMda = true; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // construct tag |
| 105 | 105 | $tag .= "<$name "; |
| 106 | 106 | |
| 107 | - foreach ( $attr as $k => $v ) { |
|
| 107 | + foreach ($attr as $k => $v) { |
|
| 108 | 108 | //normal tag flux, put attributes in it but skip for translation state and set the right value for the attribute |
| 109 | - if ( $k != 'state' ) { |
|
| 109 | + if ($k != 'state') { |
|
| 110 | 110 | $tag .= "$k=\"$v\" "; |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $seg = $this->getCurrentSegment(); |
| 115 | 115 | |
| 116 | - if ( $name === $this->tuTagName && !empty( $seg ) && isset( $seg[ 'sid' ] ) ) { |
|
| 116 | + if ($name === $this->tuTagName && !empty($seg) && isset($seg['sid'])) { |
|
| 117 | 117 | |
| 118 | 118 | // add `matecat:segment-id` to xliff v.2* |
| 119 | - if ( strpos( $tag, 'matecat:segment-id' ) === false ) { |
|
| 120 | - $tag .= "matecat:segment-id=\"{$seg[ 'sid' ]}\" "; |
|
| 119 | + if (strpos($tag, 'matecat:segment-id') === false) { |
|
| 120 | + $tag .= "matecat:segment-id=\"{$seg['sid']}\" "; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // replace state for xliff v2 |
| 126 | - if ( 'segment' === $name ) { // add state to segment in Xliff v2 |
|
| 127 | - [ $stateProp, ] = StatusToStateAttribute::getState( $this->xliffVersion, $seg[ 'status' ] ); |
|
| 126 | + if ('segment' === $name) { // add state to segment in Xliff v2 |
|
| 127 | + [$stateProp, ] = StatusToStateAttribute::getState($this->xliffVersion, $seg['status']); |
|
| 128 | 128 | $tag .= $stateProp; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $tag = $this->handleOpenXliffTag( $name, $attr, $tag ); |
|
| 131 | + $tag = $this->handleOpenXliffTag($name, $attr, $tag); |
|
| 132 | 132 | |
| 133 | - $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
|
| 133 | + $this->checkForSelfClosedTagAndFlush($parser, $tag); |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - protected function handleOpenXliffTag( string $name, array $attr, string $tag ): string { |
|
| 147 | - $tag = parent::handleOpenXliffTag( $name, $attr, $tag ); |
|
| 146 | + protected function handleOpenXliffTag(string $name, array $attr, string $tag): string { |
|
| 147 | + $tag = parent::handleOpenXliffTag($name, $attr, $tag); |
|
| 148 | 148 | // add oasis xliff 20 namespace |
| 149 | - if ( $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) { |
|
| 149 | + if ($name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) { |
|
| 150 | 150 | $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"'; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | /** |
| 157 | 157 | * @inheritDoc |
| 158 | 158 | */ |
| 159 | - protected function tagClose( $parser, string $name ) { |
|
| 159 | + protected function tagClose($parser, string $name) { |
|
| 160 | 160 | $tag = ''; |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -165,32 +165,32 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * self::tagOpen method |
| 167 | 167 | */ |
| 168 | - if ( !$this->isEmpty ) { |
|
| 168 | + if (!$this->isEmpty) { |
|
| 169 | 169 | |
| 170 | - if ( !$this->inTarget ) { |
|
| 170 | + if (!$this->inTarget) { |
|
| 171 | 171 | $tag = "</$name>"; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - if ( 'target' == $name && !$this->inAltTrans ) { |
|
| 174 | + if ('target' == $name && !$this->inAltTrans) { |
|
| 175 | 175 | |
| 176 | - if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
|
| 176 | + if (isset($this->transUnits[$this->currentTransUnitId])) { |
|
| 177 | 177 | |
| 178 | 178 | $seg = $this->getCurrentSegment(); |
| 179 | 179 | |
| 180 | 180 | // update counts |
| 181 | - if ( !$this->hasWrittenCounts && !empty( $seg ) ) { |
|
| 182 | - $this->updateSegmentCounts( $seg ); |
|
| 181 | + if (!$this->hasWrittenCounts && !empty($seg)) { |
|
| 182 | + $this->updateSegmentCounts($seg); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // delete translations so the prepareSegment |
| 186 | 186 | // will put source content in target tag |
| 187 | - if ( $this->sourceInTarget ) { |
|
| 188 | - $seg[ 'translation' ] = ''; |
|
| 187 | + if ($this->sourceInTarget) { |
|
| 188 | + $seg['translation'] = ''; |
|
| 189 | 189 | $this->resetCounts(); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // append $translation |
| 193 | - $translation = $this->prepareTranslation( $seg ); |
|
| 193 | + $translation = $this->prepareTranslation($seg); |
|
| 194 | 194 | |
| 195 | 195 | //append translation |
| 196 | 196 | $tag = "<target>$translation</target>"; |
@@ -200,22 +200,22 @@ discard block |
||
| 200 | 200 | // signal we are leaving a target |
| 201 | 201 | $this->targetWasWritten = true; |
| 202 | 202 | $this->inTarget = false; |
| 203 | - $this->postProcAndFlush( $this->outputFP, $tag, true ); |
|
| 203 | + $this->postProcAndFlush($this->outputFP, $tag, true); |
|
| 204 | 204 | |
| 205 | - } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
|
| 205 | + } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section |
|
| 206 | 206 | |
| 207 | 207 | $this->bufferIsActive = false; |
| 208 | 208 | |
| 209 | 209 | // only for Xliff 2.* |
| 210 | 210 | // write here <mda:metaGroup> and <mda:meta> if already present in the <unit> |
| 211 | - if ( 'mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts ) { |
|
| 211 | + if ('mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts) { |
|
| 212 | 212 | |
| 213 | 213 | // we need to update counts here |
| 214 | 214 | $this->updateCounts(); |
| 215 | 215 | $this->hasWrittenCounts = true; |
| 216 | 216 | |
| 217 | 217 | $tag = $this->CDATABuffer; |
| 218 | - $tag .= $this->getWordCountGroupForXliffV2( false ); |
|
| 218 | + $tag .= $this->getWordCountGroupForXliffV2(false); |
|
| 219 | 219 | $tag .= " </mda:metadata>"; |
| 220 | 220 | |
| 221 | 221 | } else { |
@@ -225,19 +225,19 @@ discard block |
||
| 225 | 225 | $this->CDATABuffer = ""; |
| 226 | 226 | |
| 227 | 227 | //flush to the pointer |
| 228 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 228 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 229 | 229 | |
| 230 | - } elseif ( 'segment' === $name ) { |
|
| 230 | + } elseif ('segment' === $name) { |
|
| 231 | 231 | |
| 232 | 232 | // only for Xliff 2.* |
| 233 | 233 | // if segment has no <target> add it BEFORE </segment> |
| 234 | - if ( !$this->targetWasWritten ) { |
|
| 234 | + if (!$this->targetWasWritten) { |
|
| 235 | 235 | |
| 236 | 236 | $seg = $this->getCurrentSegment(); |
| 237 | 237 | |
| 238 | - if ( isset( $seg[ 'translation' ] ) ) { |
|
| 238 | + if (isset($seg['translation'])) { |
|
| 239 | 239 | |
| 240 | - $translation = $this->prepareTranslation( $seg ); |
|
| 240 | + $translation = $this->prepareTranslation($seg); |
|
| 241 | 241 | // replace the tag |
| 242 | 242 | $tag = "<target>$translation</target>"; |
| 243 | 243 | |
@@ -250,19 +250,19 @@ discard block |
||
| 250 | 250 | // update segmentPositionInTu |
| 251 | 251 | $this->segmentInUnitPosition++; |
| 252 | 252 | |
| 253 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 253 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 254 | 254 | |
| 255 | 255 | // we are leaving <segment>, reset $segmentHasTarget |
| 256 | 256 | $this->targetWasWritten = false; |
| 257 | 257 | |
| 258 | - } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
| 258 | + } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
|
| 259 | 259 | $this->CDATABuffer .= "</$name>"; |
| 260 | 260 | // Do NOT Flush |
| 261 | 261 | } else { //generic tag closure do Nothing |
| 262 | 262 | // flush to pointer |
| 263 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 263 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 264 | 264 | } |
| 265 | - } elseif ( in_array( $name, $this->nodesToBuffer ) ) { |
|
| 265 | + } elseif (in_array($name, $this->nodesToBuffer)) { |
|
| 266 | 266 | |
| 267 | 267 | $this->isEmpty = false; |
| 268 | 268 | $this->bufferIsActive = false; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $this->CDATABuffer = ""; |
| 271 | 271 | |
| 272 | 272 | //flush to the pointer |
| 273 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
| 273 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
| 274 | 274 | |
| 275 | 275 | } else { |
| 276 | 276 | //ok, nothing to be done; reset flag for next coming tag |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | // try to signal that we are leaving a target |
| 281 | - $this->tryUnsetAltTrans( $name ); |
|
| 281 | + $this->tryUnsetAltTrans($name); |
|
| 282 | 282 | |
| 283 | 283 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
| 284 | - if ( $this->tuTagName === $name ) { |
|
| 284 | + if ($this->tuTagName === $name) { |
|
| 285 | 285 | $this->currentTransUnitIsTranslatable = null; |
| 286 | 286 | $this->inTU = false; |
| 287 | 287 | $this->unitContainsMda = false; |
@@ -297,8 +297,8 @@ discard block |
||
| 297 | 297 | private function updateCounts() { |
| 298 | 298 | |
| 299 | 299 | $seg = $this->getCurrentSegment(); |
| 300 | - if ( !empty( $seg ) ) { |
|
| 301 | - $this->updateSegmentCounts( $seg ); |
|
| 300 | + if (!empty($seg)) { |
|
| 301 | + $this->updateSegmentCounts($seg); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | } |
@@ -308,30 +308,30 @@ discard block |
||
| 308 | 308 | * |
| 309 | 309 | * @return string |
| 310 | 310 | */ |
| 311 | - private function getWordCountGroupForXliffV2( bool $withMetadataTag = true ): string { |
|
| 311 | + private function getWordCountGroupForXliffV2(bool $withMetadataTag = true): string { |
|
| 312 | 312 | |
| 313 | 313 | $this->mdaGroupCounter++; |
| 314 | - $segments_count_array = $this->counts[ 'segments_count_array' ]; |
|
| 314 | + $segments_count_array = $this->counts['segments_count_array']; |
|
| 315 | 315 | |
| 316 | 316 | $tag = ''; |
| 317 | 317 | |
| 318 | - if ( $withMetadataTag === true ) { |
|
| 318 | + if ($withMetadataTag === true) { |
|
| 319 | 319 | $tag .= '<mda:metadata>'; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | $index = 0; |
| 323 | - foreach ( $segments_count_array as $segments_count_item ) { |
|
| 323 | + foreach ($segments_count_array as $segments_count_item) { |
|
| 324 | 324 | |
| 325 | 325 | $id = 'word_count_tu.' . $this->currentTransUnitId . '.' . $index; |
| 326 | 326 | $index++; |
| 327 | 327 | |
| 328 | 328 | $tag .= " <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\"> |
| 329 | - <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta> |
|
| 330 | - <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta> |
|
| 329 | + <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta> |
|
| 330 | + <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta> |
|
| 331 | 331 | </mda:metaGroup>"; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if ( $withMetadataTag === true ) { |
|
| 334 | + if ($withMetadataTag === true) { |
|
| 335 | 335 | $tag .= '</mda:metadata>'; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -346,18 +346,18 @@ discard block |
||
| 346 | 346 | * |
| 347 | 347 | * @return string |
| 348 | 348 | */ |
| 349 | - protected function prepareTranslation( array $seg ): string { |
|
| 349 | + protected function prepareTranslation(array $seg): string { |
|
| 350 | 350 | |
| 351 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
| 352 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
| 353 | - $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
|
| 351 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
| 352 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
| 353 | + $dataRefMap = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : []; |
|
| 354 | 354 | |
| 355 | - if ( $seg [ 'translation' ] == '' ) { |
|
| 355 | + if ($seg ['translation'] == '') { |
|
| 356 | 356 | $translation = $segment; |
| 357 | 357 | } else { |
| 358 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
| 359 | - $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null; |
|
| 360 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
|
| 358 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
| 359 | + $error = (!empty($seg['error'])) ? $seg['error'] : null; |
|
| 360 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) { |
|
| 361 | 361 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
| 362 | 362 | } |
| 363 | 363 | } |