@@ -8,20 +8,20 @@ |
||
8 | 8 | * |
9 | 9 | * @return array|null |
10 | 10 | */ |
11 | - public function check( $tmp ) { |
|
11 | + public function check($tmp) { |
|
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,5 +8,5 @@ |
||
8 | 8 | * |
9 | 9 | * @return array|null |
10 | 10 | */ |
11 | - public function check( $tmp ); |
|
11 | + public function check($tmp); |
|
12 | 12 | } |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | /** |
10 | 10 | * @var array |
11 | 11 | */ |
12 | - private static $versions_1 = [ '1.0', '1.1', '1.2' ]; |
|
12 | + private static $versions_1 = ['1.0', '1.1', '1.2']; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * @var array |
16 | 16 | */ |
17 | - private static $versions_2 = [ '2.0', '2.1' ]; |
|
17 | + private static $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( $xliffContent ) { |
|
27 | - preg_match( '|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr( $xliffContent, 0, 1000 ), $versionMatches ); |
|
26 | + public static function detect($xliffContent) { |
|
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( $version ) { |
|
45 | - if ( in_array( $version, self::$versions_1 ) ) { |
|
44 | + private static function resolveVersion($version) { |
|
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 | } |
@@ -18,13 +18,13 @@ |
||
18 | 18 | * |
19 | 19 | * @return SdlXliffSAXTranslationReplacer|XliffSAXTranslationReplacer |
20 | 20 | */ |
21 | - public static function getInstance( $originalXliffPath, &$data, &$transUnits, $targetLang, $outputFilePath, $setSourceInTarget, LoggerInterface $logger = null, XliffReplacerCallbackInterface $callback = null ) { |
|
22 | - $info = XliffProprietaryDetect::getInfo( $originalXliffPath ); |
|
21 | + public static function getInstance($originalXliffPath, &$data, &$transUnits, $targetLang, $outputFilePath, $setSourceInTarget, LoggerInterface $logger = null, XliffReplacerCallbackInterface $callback = null) { |
|
22 | + $info = XliffProprietaryDetect::getInfo($originalXliffPath); |
|
23 | 23 | |
24 | - if ( $info[ 'proprietary_short_name' ] !== 'trados' ) { |
|
25 | - return new XliffSAXTranslationReplacer( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
24 | + if ($info['proprietary_short_name'] !== 'trados') { |
|
25 | + return new XliffSAXTranslationReplacer($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
26 | 26 | } |
27 | 27 | |
28 | - return new SdlXliffSAXTranslationReplacer( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
28 | + return new SdlXliffSAXTranslationReplacer($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
29 | 29 | } |
30 | 30 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param LoggerInterface $logger |
26 | 26 | */ |
27 | - public function __construct( LoggerInterface $logger = null ) { |
|
27 | + public function __construct(LoggerInterface $logger = null) { |
|
28 | 28 | $this->logger = $logger; |
29 | 29 | } |
30 | 30 | |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | * @param bool $setSourceInTarget |
40 | 40 | * @param XliffReplacerCallbackInterface|null $callback |
41 | 41 | */ |
42 | - public function replaceTranslation( $originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null ) { |
|
42 | + public function replaceTranslation($originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null) { |
|
43 | 43 | try { |
44 | - $parser = XliffReplacerFactory::getInstance( $originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback ); |
|
44 | + $parser = XliffReplacerFactory::getInstance($originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback); |
|
45 | 45 | $parser->replaceTranslation(); |
46 | - } catch ( \Exception $exception ) { |
|
46 | + } catch (\Exception $exception) { |
|
47 | 47 | // do nothing |
48 | 48 | } |
49 | 49 | } |
@@ -61,29 +61,29 @@ discard block |
||
61 | 61 | * @throws Exception\NotValidFileException |
62 | 62 | * @throws Exception\XmlParsingException |
63 | 63 | */ |
64 | - public function xliffToArray( $xliffContent, $collapseEmptyTags = false ) { |
|
64 | + public function xliffToArray($xliffContent, $collapseEmptyTags = false) { |
|
65 | 65 | $xliff = []; |
66 | - $xliffContent = self::forceUft8Encoding( $xliffContent, $xliff ); |
|
67 | - $xliffVersion = XliffVersionDetector::detect( $xliffContent ); |
|
68 | - $info = XliffProprietaryDetect::getInfoFromXliffContent( $xliffContent ); |
|
66 | + $xliffContent = self::forceUft8Encoding($xliffContent, $xliff); |
|
67 | + $xliffVersion = XliffVersionDetector::detect($xliffContent); |
|
68 | + $info = XliffProprietaryDetect::getInfoFromXliffContent($xliffContent); |
|
69 | 69 | |
70 | - if ( $xliffVersion === 1 ) { |
|
71 | - $xliffContent = self::removeInternalFileTagFromContent( $xliffContent, $xliff ); |
|
70 | + if ($xliffVersion === 1) { |
|
71 | + $xliffContent = self::removeInternalFileTagFromContent($xliffContent, $xliff); |
|
72 | 72 | } |
73 | 73 | |
74 | - if ( $xliffVersion === 2 ) { |
|
75 | - $xliffContent = self::escapeDataInOriginalMap( $xliffContent ); |
|
74 | + if ($xliffVersion === 2) { |
|
75 | + $xliffContent = self::escapeDataInOriginalMap($xliffContent); |
|
76 | 76 | } |
77 | 77 | |
78 | - if ( $collapseEmptyTags === false ) { |
|
79 | - $xliffContent = self::insertPlaceholderInEmptyTags( $xliffContent ); |
|
78 | + if ($collapseEmptyTags === false) { |
|
79 | + $xliffContent = self::insertPlaceholderInEmptyTags($xliffContent); |
|
80 | 80 | } |
81 | 81 | |
82 | - $xliffProprietary = ( isset( $info[ 'proprietary_short_name' ] ) && null !== $info[ 'proprietary_short_name' ] ) ? $info[ 'proprietary_short_name' ] : null; |
|
83 | - $parser = XliffParserFactory::getInstance( $xliffVersion, $xliffProprietary, $this->logger ); |
|
84 | - $dom = XmlParser::parse( $xliffContent ); |
|
82 | + $xliffProprietary = (isset($info['proprietary_short_name']) && null !== $info['proprietary_short_name']) ? $info['proprietary_short_name'] : null; |
|
83 | + $parser = XliffParserFactory::getInstance($xliffVersion, $xliffProprietary, $this->logger); |
|
84 | + $dom = XmlParser::parse($xliffContent); |
|
85 | 85 | |
86 | - return $parser->parse( $dom, $xliff ); |
|
86 | + return $parser->parse($dom, $xliff); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string |
97 | 97 | */ |
98 | - private static function forceUft8Encoding( $xliffContent, &$xliff ) { |
|
99 | - $enc = mb_detect_encoding( $xliffContent ); |
|
98 | + private static function forceUft8Encoding($xliffContent, &$xliff) { |
|
99 | + $enc = mb_detect_encoding($xliffContent); |
|
100 | 100 | |
101 | - if ( $enc !== 'UTF-8' ) { |
|
102 | - $xliff[ 'parser-warnings' ][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only"; |
|
103 | - $s = iconv( $enc, 'UTF-8', $xliffContent ); |
|
101 | + if ($enc !== 'UTF-8') { |
|
102 | + $xliff['parser-warnings'][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only"; |
|
103 | + $s = iconv($enc, 'UTF-8', $xliffContent); |
|
104 | 104 | $xliffContent = $s !== false ? $s : ""; |
105 | 105 | } |
106 | 106 | |
@@ -117,24 +117,24 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @return mixed|string |
119 | 119 | */ |
120 | - private static function removeInternalFileTagFromContent( $xliffContent, &$xliff ) { |
|
120 | + private static function removeInternalFileTagFromContent($xliffContent, &$xliff) { |
|
121 | 121 | $index = 1; |
122 | - $a = Strings::preg_split( '|<internal-file[\s>]|si', $xliffContent ); |
|
122 | + $a = Strings::preg_split('|<internal-file[\s>]|si', $xliffContent); |
|
123 | 123 | |
124 | 124 | // no match, return original string |
125 | - if ( count( $a ) === 1 ) { |
|
126 | - return $a[ 0 ]; |
|
125 | + if (count($a) === 1) { |
|
126 | + return $a[0]; |
|
127 | 127 | } |
128 | 128 | |
129 | - $b = Strings::preg_split( '|</internal-file>|si', $a[ 1 ] ); |
|
130 | - $strippedContent = $a[ 0 ] . $b[ 1 ]; |
|
131 | - $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $b[ 0 ] ); |
|
129 | + $b = Strings::preg_split('|</internal-file>|si', $a[1]); |
|
130 | + $strippedContent = $a[0] . $b[1]; |
|
131 | + $xliff['files'][$index]['reference'][] = self::extractBase64($b[0]); |
|
132 | 132 | $index++; |
133 | 133 | |
134 | - if ( isset( $a[ 2 ] ) ) { |
|
135 | - $c = Strings::preg_split( '|</internal-file[\s>]|si', $a[ 2 ] ); |
|
136 | - $strippedContent .= $c[ 1 ]; |
|
137 | - $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $c[ 0 ] ); |
|
134 | + if (isset($a[2])) { |
|
135 | + $c = Strings::preg_split('|</internal-file[\s>]|si', $a[2]); |
|
136 | + $strippedContent .= $c[1]; |
|
137 | + $xliff['files'][$index]['reference'][] = self::extractBase64($c[0]); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return $strippedContent; |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return array |
147 | 147 | */ |
148 | - private static function extractBase64( $base64 ) { |
|
148 | + private static function extractBase64($base64) { |
|
149 | 149 | return [ |
150 | 150 | 'form-type' => 'base64', |
151 | - 'base64' => trim( str_replace( 'form="base64">', '', $base64 ) ), |
|
151 | + 'base64' => trim(str_replace('form="base64">', '', $base64)), |
|
152 | 152 | ]; |
153 | 153 | } |
154 | 154 | |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - private static function escapeDataInOriginalMap( $xliffContent ) { |
|
172 | - $xliffContent = preg_replace_callback( '/<data(.*?)>(.*?)<\/data>/iU', [ XliffParser::class, 'replaceSpace' ], $xliffContent ); |
|
173 | - $xliffContent = preg_replace_callback( '/<data(.*?)>(.*?)<\/data>/iU', [ XliffParser::class, 'replaceXliffTags' ], $xliffContent ); |
|
171 | + private static function escapeDataInOriginalMap($xliffContent) { |
|
172 | + $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceSpace'], $xliffContent); |
|
173 | + $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceXliffTags'], $xliffContent); |
|
174 | 174 | |
175 | 175 | return $xliffContent; |
176 | 176 | } |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | * |
190 | 190 | * @return string |
191 | 191 | */ |
192 | - private static function insertPlaceholderInEmptyTags( $xliffContent ) { |
|
193 | - preg_match_all( '/<([a-zA-Z0-9._-]+)[^>]*><\/\1>/sm', $xliffContent, $emptyTagMatches ); |
|
192 | + private static function insertPlaceholderInEmptyTags($xliffContent) { |
|
193 | + preg_match_all('/<([a-zA-Z0-9._-]+)[^>]*><\/\1>/sm', $xliffContent, $emptyTagMatches); |
|
194 | 194 | |
195 | - if ( !empty( $emptyTagMatches[ 0 ] ) ) { |
|
196 | - foreach ( $emptyTagMatches[ 0 ] as $index => $emptyTagMatch ) { |
|
197 | - $matchedTag = $emptyTagMatches[ 1 ][ $index ]; |
|
195 | + if (!empty($emptyTagMatches[0])) { |
|
196 | + foreach ($emptyTagMatches[0] as $index => $emptyTagMatch) { |
|
197 | + $matchedTag = $emptyTagMatches[1][$index]; |
|
198 | 198 | $subst = Placeholder::EMPTY_TAG_PLACEHOLDER . '</' . $matchedTag . '>'; |
199 | - $replacedTag = str_replace( '</' . $matchedTag . '>', $subst, $emptyTagMatch ); |
|
200 | - $xliffContent = str_replace( $emptyTagMatch, $replacedTag, $xliffContent ); |
|
199 | + $replacedTag = str_replace('</' . $matchedTag . '>', $subst, $emptyTagMatch); |
|
200 | + $xliffContent = str_replace($emptyTagMatch, $replacedTag, $xliffContent); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
@@ -211,12 +211,12 @@ discard block |
||
211 | 211 | * |
212 | 212 | * @return string |
213 | 213 | */ |
214 | - private static function replaceSpace( $matches ) { |
|
215 | - $content = str_replace( ' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[ 2 ] ); |
|
216 | - $content = str_replace( '\n', Placeholder::NEW_LINE_PLACEHOLDER, $content ); |
|
217 | - $content = str_replace( '\t', Placeholder::TAB_PLACEHOLDER, $content ); |
|
214 | + private static function replaceSpace($matches) { |
|
215 | + $content = str_replace(' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[2]); |
|
216 | + $content = str_replace('\n', Placeholder::NEW_LINE_PLACEHOLDER, $content); |
|
217 | + $content = str_replace('\t', Placeholder::TAB_PLACEHOLDER, $content); |
|
218 | 218 | |
219 | - return '<data' . $matches[ 1 ] . '>' . $content . '</data>'; |
|
219 | + return '<data' . $matches[1] . '>' . $content . '</data>'; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -224,15 +224,15 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - private static function replaceXliffTags( $matches ) { |
|
227 | + private static function replaceXliffTags($matches) { |
|
228 | 228 | $xliffTags = XliffTags::$tags; |
229 | - $content = $matches[ 2 ]; |
|
229 | + $content = $matches[2]; |
|
230 | 230 | |
231 | - foreach ( $xliffTags as $xliffTag ) { |
|
232 | - $content = preg_replace( '|<(' . $xliffTag . '.*?)>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content ); |
|
233 | - $content = preg_replace( '|<(/' . $xliffTag . ')>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content ); |
|
231 | + foreach ($xliffTags as $xliffTag) { |
|
232 | + $content = preg_replace('|<(' . $xliffTag . '.*?)>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content); |
|
233 | + $content = preg_replace('|<(/' . $xliffTag . ')>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content); |
|
234 | 234 | } |
235 | 235 | |
236 | - return '<data' . $matches[ 1 ] . '>' . $content . '</data>'; |
|
236 | + return '<data' . $matches[1] . '>' . $content . '</data>'; |
|
237 | 237 | } |
238 | 238 | } |
@@ -8,14 +8,14 @@ |
||
8 | 8 | * https://stackoverflow.com/questions/11427398/how-to-implode-array-with-key-and-value-without-foreach-in-php |
9 | 9 | */ |
10 | 10 | class FlatData { |
11 | - public static function flatArray( array $input = [], $separator_elements = ', ', $separator = ': ' ) { |
|
12 | - return implode( $separator_elements, array_map( |
|
13 | - function ( $v, $k, $s ) { |
|
14 | - return sprintf( "%s{$s}\"%s\"", $k, $v ); |
|
11 | + public static function flatArray(array $input = [], $separator_elements = ', ', $separator = ': ') { |
|
12 | + return implode($separator_elements, array_map( |
|
13 | + function($v, $k, $s) { |
|
14 | + return sprintf("%s{$s}\"%s\"", $k, $v); |
|
15 | 15 | }, |
16 | 16 | $input, |
17 | - array_keys( $input ), |
|
18 | - array_fill( 0, count( $input ), $separator ) |
|
19 | - ) ); |
|
17 | + array_keys($input), |
|
18 | + array_fill(0, count($input), $separator) |
|
19 | + )); |
|
20 | 20 | } |
21 | 21 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | * |
13 | 13 | * @return AbstractXliffParser |
14 | 14 | */ |
15 | - public static function getInstance( $xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null ) { |
|
15 | + public static function getInstance($xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null) { |
|
16 | 16 | $parserClass = 'Matecat\\XliffParser\\XliffParser\\XliffParserV' . $xliffVersion; |
17 | 17 | |
18 | 18 | /** @var AbstractXliffParser $parser */ |
19 | - return new $parserClass( $xliffVersion, $xliffProprietary, $logger ); |
|
19 | + return new $parserClass($xliffVersion, $xliffProprietary, $logger); |
|
20 | 20 | } |
21 | 21 | } |
@@ -11,5 +11,5 @@ |
||
11 | 11 | * @param null $error |
12 | 12 | * @return bool |
13 | 13 | */ |
14 | - public function thereAreErrors( $segmentId, $segment, $translation, array $dataRefMap = [], $error = null ); |
|
14 | + public function thereAreErrors($segmentId, $segment, $translation, array $dataRefMap = [], $error = null); |
|
15 | 15 | } |
@@ -10,22 +10,22 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * @inheritDoc |
12 | 12 | */ |
13 | - protected function tagOpen( $parser, $name, $attr ) { |
|
13 | + protected function tagOpen($parser, $name, $attr) { |
|
14 | 14 | // check if we are entering into a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
15 | - if ( $this->tuTagName === $name ) { |
|
15 | + if ($this->tuTagName === $name) { |
|
16 | 16 | $this->inTU = true; |
17 | 17 | |
18 | 18 | // get id |
19 | 19 | // trim to first 100 characters because this is the limit on Matecat's DB |
20 | - $this->currentTransUnitId = substr( $attr[ 'id' ], 0, 100 ); |
|
20 | + $this->currentTransUnitId = substr($attr['id'], 0, 100); |
|
21 | 21 | |
22 | 22 | // current 'translate' attribute of the current trans-unit |
23 | - $this->currentTransUnitTranslate = isset( $attr[ 'translate' ] ) ? $attr[ 'translate' ] : 'yes'; |
|
23 | + $this->currentTransUnitTranslate = isset($attr['translate']) ? $attr['translate'] : 'yes'; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // check if we are entering into a <target> |
27 | - if ( 'target' == $name ) { |
|
28 | - if ( $this->currentTransUnitTranslate === 'no' ) { |
|
27 | + if ('target' == $name) { |
|
28 | + if ($this->currentTransUnitTranslate === 'no') { |
|
29 | 29 | $this->inTarget = false; |
30 | 30 | } else { |
31 | 31 | $this->inTarget = true; |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | // reset Marker positions |
36 | - if ( 'sdl:seg-defs' == $name ) { |
|
36 | + if ('sdl:seg-defs' == $name) { |
|
37 | 37 | $this->markerPos = 0; |
38 | 38 | } |
39 | 39 | |
40 | 40 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
41 | 41 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
42 | - if ( !$this->inTarget ) { |
|
42 | + if (!$this->inTarget) { |
|
43 | 43 | |
44 | 44 | // costruct tag |
45 | 45 | $tag = "<$name "; |
@@ -49,23 +49,23 @@ discard block |
||
49 | 49 | // so the check on it's name is not enough |
50 | 50 | $_sdlStatus_confWritten = false; |
51 | 51 | |
52 | - foreach ( $attr as $k => $v ) { |
|
52 | + foreach ($attr as $k => $v) { |
|
53 | 53 | |
54 | 54 | // if tag name is file, we must replace the target-language attribute |
55 | - if ( $name == 'file' && $k == 'target-language' && !empty( $this->targetLang ) ) { |
|
55 | + if ($name == 'file' && $k == 'target-language' && !empty($this->targetLang)) { |
|
56 | 56 | //replace Target language with job language provided from constructor |
57 | 57 | $tag .= "$k=\"$this->targetLang\" "; |
58 | 58 | |
59 | - if ( null !== $this->logger ) { |
|
60 | - $this->logger->debug( $k . " => " . $this->targetLang ); |
|
59 | + if (null !== $this->logger) { |
|
60 | + $this->logger->debug($k . " => " . $this->targetLang); |
|
61 | 61 | } |
62 | - } elseif ( 'sdl:seg' == $name ) { |
|
62 | + } elseif ('sdl:seg' == $name) { |
|
63 | 63 | |
64 | 64 | // write the confidence level for this segment ( Translated, Draft, etc. ) |
65 | - if ( isset( $this->segments[ 'matecat|' . $this->currentTransUnitId ] ) && $_sdlStatus_confWritten === false ) { |
|
65 | + if (isset($this->segments['matecat|' . $this->currentTransUnitId]) && $_sdlStatus_confWritten === false) { |
|
66 | 66 | |
67 | 67 | // append definition attribute |
68 | - $tag .= $this->prepareTargetStatuses( $this->lastTransUnit[ $this->markerPos ] ); |
|
68 | + $tag .= $this->prepareTargetStatuses($this->lastTransUnit[$this->markerPos]); |
|
69 | 69 | |
70 | 70 | //prepare for an eventual next cycle |
71 | 71 | $this->markerPos++; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | // Warning, this is NOT an elseif |
76 | - if ( $k != 'conf' ) { |
|
76 | + if ($k != 'conf') { |
|
77 | 77 | //put also the current attribute in it if it is not a "conf" attribute |
78 | 78 | $tag .= "$k=\"$v\" "; |
79 | 79 | } |
@@ -86,29 +86,29 @@ discard block |
||
86 | 86 | // this logic helps detecting empty tags |
87 | 87 | // get current position of SAX pointer in all the stream of data is has read so far: |
88 | 88 | // it points at the end of current tag |
89 | - $idx = xml_get_current_byte_index( $parser ); |
|
89 | + $idx = xml_get_current_byte_index($parser); |
|
90 | 90 | |
91 | 91 | // check whether the bounds of current tag are entirely in current buffer || the end of the current tag |
92 | 92 | // is outside current buffer (in the latter case, it's in next buffer to be read by the while loop); |
93 | 93 | // this check is necessary because we may have truncated a tag in half with current read, |
94 | 94 | // and the other half may be encountered in the next buffer it will be passed |
95 | - if ( isset( $this->currentBuffer[ $idx - $this->offset ] ) ) { |
|
95 | + if (isset($this->currentBuffer[$idx - $this->offset])) { |
|
96 | 96 | // if this tag entire lenght fitted in the buffer, the last char must be the last |
97 | 97 | // symbol before the '>'; if it's an empty tag, it is assumed that it's a '/' |
98 | 98 | $tmp_offset = $idx - $this->offset; |
99 | - $lastChar = $this->currentBuffer[ $tmp_offset ]; |
|
99 | + $lastChar = $this->currentBuffer[$tmp_offset]; |
|
100 | 100 | } else { |
101 | 101 | //if it's out, simple use the last character of the chunk |
102 | 102 | $tmp_offset = $this->len - 1; |
103 | - $lastChar = $this->currentBuffer[ $tmp_offset ]; |
|
103 | + $lastChar = $this->currentBuffer[$tmp_offset]; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // trim last space |
107 | - $tag = rtrim( $tag ); |
|
107 | + $tag = rtrim($tag); |
|
108 | 108 | |
109 | 109 | // detect empty tag |
110 | - $this->isEmpty = ( $lastChar == '/' || $name == 'x' ); |
|
111 | - if ( $this->isEmpty ) { |
|
110 | + $this->isEmpty = ($lastChar == '/' || $name == 'x'); |
|
111 | + if ($this->isEmpty) { |
|
112 | 112 | $tag .= '/'; |
113 | 113 | } |
114 | 114 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $tag .= ">"; |
117 | 117 | |
118 | 118 | // set a a Buffer for the segSource Source tag |
119 | - if ( 'source' == $name |
|
119 | + if ('source' == $name |
|
120 | 120 | || 'seg-source' === $name |
121 | 121 | || $this->bufferIsActive |
122 | 122 | || 'value' === $name |
@@ -125,19 +125,19 @@ discard block |
||
125 | 125 | || 'ph' === $name |
126 | 126 | || 'st' === $name |
127 | 127 | || 'note' === $name |
128 | - || 'context' === $name ) { // we are opening a critical CDATA section |
|
128 | + || 'context' === $name) { // we are opening a critical CDATA section |
|
129 | 129 | |
130 | 130 | // WARNING BECAUSE SOURCE AND SEG-SOURCE TAGS CAN BE EMPTY IN SOME CASES!!!!! |
131 | 131 | // so check for isEmpty also in conjunction with name |
132 | - if ( $this->isEmpty && ( 'source' == $name || 'seg-source' == $name ) ) { |
|
133 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
132 | + if ($this->isEmpty && ('source' == $name || 'seg-source' == $name)) { |
|
133 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
134 | 134 | } else { |
135 | 135 | //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer |
136 | 136 | $this->bufferIsActive = true; |
137 | - $this->CDATABuffer .= $tag; |
|
137 | + $this->CDATABuffer .= $tag; |
|
138 | 138 | } |
139 | 139 | } else { |
140 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
140 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | } |
@@ -150,19 +150,19 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - protected function prepareTranslation( $seg, $transUnitTranslation = "" ) { |
|
153 | + protected function prepareTranslation($seg, $transUnitTranslation = "") { |
|
154 | 154 | $endTags = ""; |
155 | 155 | |
156 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
157 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
158 | - $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) && $seg[ 'data_ref_map' ] !== null ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
|
156 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
157 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
158 | + $dataRefMap = (isset($seg['data_ref_map']) && $seg['data_ref_map'] !== null) ? Strings::jsonToArray($seg['data_ref_map']) : []; |
|
159 | 159 | |
160 | - if ( is_null( $seg [ 'translation' ] ) || $seg [ 'translation' ] == '' ) { |
|
160 | + if (is_null($seg ['translation']) || $seg ['translation'] == '') { |
|
161 | 161 | $translation = $segment; |
162 | 162 | } else { |
163 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
163 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
164 | 164 | $error = (isset($seg['error'])) ? $seg['error'] : null; |
165 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
|
165 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) { |
|
166 | 166 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
167 | 167 | } |
168 | 168 | } |
@@ -171,20 +171,20 @@ discard block |
||
171 | 171 | // for Trados the trailing spaces after </mrk> are meaningful |
172 | 172 | // so we trim the translation from Matecat DB and add them after </mrk> |
173 | 173 | $trailingSpaces = ''; |
174 | - for ( $s = 0; $s < Strings::getTheNumberOfTrailingSpaces( $translation ); $s++ ) { |
|
174 | + for ($s = 0; $s < Strings::getTheNumberOfTrailingSpaces($translation); $s++) { |
|
175 | 175 | $trailingSpaces .= ' '; |
176 | 176 | } |
177 | 177 | |
178 | - if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
|
179 | - if ( $this->targetLang === 'ja-JP' ) { |
|
180 | - $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] ); |
|
178 | + if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') { |
|
179 | + if ($this->targetLang === 'ja-JP') { |
|
180 | + $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']); |
|
181 | 181 | } |
182 | 182 | |
183 | - $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . rtrim( $translation ) . $seg[ 'mrk_succ_tags' ] . "</mrk>" . $trailingSpaces; |
|
183 | + $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . rtrim($translation) . $seg['mrk_succ_tags'] . "</mrk>" . $trailingSpaces; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // we need to trim succ_tags here because we already added the trailing spaces after </mrk> |
187 | - $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . ltrim( $seg[ 'succ_tags' ] ); |
|
187 | + $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . ltrim($seg['succ_tags']); |
|
188 | 188 | |
189 | 189 | return $transUnitTranslation; |
190 | 190 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @return string |
196 | 196 | */ |
197 | - protected function prepareTargetStatuses( $segment ) { |
|
197 | + protected function prepareTargetStatuses($segment) { |
|
198 | 198 | $statusMap = [ |
199 | 199 | 'NEW' => '', |
200 | 200 | 'DRAFT' => 'Draft', |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | 'REJECTED' => 'RejectedTranslation', |
204 | 204 | ]; |
205 | 205 | |
206 | - return "conf=\"{$statusMap[ $segment[ 'status' ] ]}\" "; |
|
206 | + return "conf=\"{$statusMap[$segment['status']]}\" "; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return array |
215 | 215 | */ |
216 | - protected function setTransUnitState( $seg, $state_prop, $lastMrkState ) { |
|
217 | - return [ null, null ]; |
|
216 | + protected function setTransUnitState($seg, $state_prop, $lastMrkState) { |
|
217 | + return [null, null]; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - protected function getWordCountGroup( $raw_word_count, $eq_word_count ) { |
|
226 | + protected function getWordCountGroup($raw_word_count, $eq_word_count) { |
|
227 | 227 | return ''; |
228 | 228 | } |
229 | 229 | } |