Skip to content

Commit

Permalink
Merge pull request #74 from matecat/parse-segment-state
Browse files Browse the repository at this point in the history
Parse segment attributes
  • Loading branch information
mauretto78 authored Jun 14, 2023
2 parents d28f1ae + 278490f commit 5f0015a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/XliffParser/XliffParserV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniqueness
$segSource = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $extractedSource[ 'raw-content' ], $originalData );
} else {
$segSource[] = [
'attr' => $this->extractTagAttributes( $segment),
'mid' => count( $segSource ) > 0 ? count( $segSource ) : 0,
'ext-prec-tags' => '',
'raw-content' => $extractedSource[ 'raw-content' ],
Expand All @@ -212,6 +213,7 @@ protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniqueness
$segTarget = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $extractedTarget[ 'raw-content' ], $originalData );
} else {
$segTarget[] = [
'attr' => $this->extractTagAttributes( $segment),
'mid' => count( $segTarget ) > 0 ? count( $segTarget ) : 0,
'ext-prec-tags' => '',
'raw-content' => $extractedTarget[ 'raw-content' ],
Expand Down
17 changes: 17 additions & 0 deletions tests/XliffParserV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,21 @@ public function raise_exception_on_duplicate_ids()
$this->assertEquals('Invalid trans-unit id, duplicate found.', $exception->getMessage());
}
}

/**
* @test
*/
public function can_parse_segment_state_attribute()
{
$parsed = (new XliffParser())->xliffToArray($this->getTestFile('with-segment-state.xliff'));

$this->assertEquals('0', $parsed[ 'files' ][ 1 ][ 'trans-units' ][ 1 ][ 'seg-source' ][ 0 ][ 'attr' ][ 'id' ]);
$this->assertEquals('initial', $parsed[ 'files' ][ 1 ][ 'trans-units' ][ 1 ][ 'seg-source' ][ 0 ][ 'attr' ][ 'state' ]);
$this->assertEquals('4', $parsed[ 'files' ][ 1 ][ 'trans-units' ][ 1 ][ 'seg-source' ][ 1 ][ 'attr' ][ 'id' ]);
$this->assertEquals('finale', $parsed[ 'files' ][ 1 ][ 'trans-units' ][ 1 ][ 'seg-source' ][ 1 ][ 'attr' ][ 'state' ]);
$this->assertEquals('0', $parsed[ 'files' ][ 1 ][ 'trans-units' ][ 1 ][ 'seg-target' ][ 0 ][ 'attr' ][ 'id' ]);
$this->assertEquals('initial', $parsed[ 'files' ][ 1 ][ 'trans-units' ][ 1 ][ 'seg-target' ][ 0 ][ 'attr' ][ 'state' ]);
$this->assertEquals('4', $parsed[ 'files' ][ 1 ][ 'trans-units' ][ 1 ][ 'seg-target' ][ 1 ][ 'attr' ][ 'id' ]);
$this->assertEquals('finale', $parsed[ 'files' ][ 1 ][ 'trans-units' ][ 1 ][ 'seg-target' ][ 1 ][ 'attr' ][ 'state' ]);
}
}
15 changes: 15 additions & 0 deletions tests/files/with-segment-state.xliff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US" trgLang="it-IT" xmlns:its="http://www.w3.org/2005/11/its" its:version="2.0">
<file id="kcFDnpQ2PrZx0XfO0_dc5:0-350" memsource:taskId="kcFDnpQ2PrZx0XfO0_dc5" canResegment="no" original="Direct-foundations-part-1-sp.xlf">
<unit id="0" memsource:tGroupBegin="0" memsource:tGroupEnd="0">
<segment id="0" state="initial">
<source>Direct Foundations - Part 1 - SP</source>
<target></target>
</segment>
<segment id="4" state="finale">
<source>Ciao</source>
<target>Hola</target>
</segment>
</unit>
</file>
</xliff>

0 comments on commit 5f0015a

Please sign in to comment.