8000 [Translator][Loader] added XLIFF 2.0 support. by aitboudad · Pull Request #15717 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Translator][Loader] added XLIFF 2.0 support. #15717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 16, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[XLIFF 2.0] added support for target attributes.
  • Loading branch information
aitboudad committed Sep 7, 2015
commit 7af4fc7ef8ada4310f43de290d4c6e8de66dfbf3
17 changes: 15 additions & 2 deletions src/Symfony/Component/Translation/Loader/XliffFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $
$metadata['notes'] = $notes;
10000 }
if (isset($translation->target) && $translation->target->attributes()) {
$metadata['target-attributes'] = $translation->target->attributes();
$metadata['target-attributes'] = array();
foreach ($translation->target->attributes() as $key => $value) {
$metadata['target-attributes'][$key] = (string) $value;
}
}

$catalogue->setMetadata((string) $source, $metadata, $domain);
Expand All @@ -127,9 +130,19 @@ private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, $

// If the xlf file has another encoding specified, try to convert it because
// simple_xml will always return utf-8 encoded values
$target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding);
$target = $this->utf8ToCharset((string) (isset($segment->target) ? $segment->target : $source), $encoding);

$catalogue->set((string) $source, $target, $domain);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support for notes and target attributes should be added for XLiff 2 for the equivalent features

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I'll look into it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only added support for target attributes
but for notes there's no way to do a mapping because aren't assigned to specific segments, but to whole units.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof what do you think to take account of notes only when a unit contains one segment and ignore other cases ?

<unit id="1">
    <notes>
        <note priority="1" appliesTo="target">foo</note>
    </notes>
    <segment>
        <source>foo</source>
        <target>foo</target>
    </segment>
</unit>


$metadata = array();
if (isset($segment->target) && $segment->target->attributes()) {
$metadata['target-attributes'] = array();
foreach ($segment->target->attributes() as $key => $value) {
$metadata['target-attributes'][$key] = (string) $value;
}
}

$catalogue->setMetadata((string) $source, $metadata, $domain);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function testLoadVersion2()
$this->assertCount(3, $domains['domain1']);
$this->assertContainsOnly('string', $catalogue->all('domain1'));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add $this->assertContainsOnly('string', $catalogue->all('domain1')); as in testLoad to be sure that the Xliff2 implementation does not get broken in the future by returning nodes without casting them (as done recently for Xliff 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Notes aren't assigned to specific segments, but to whole units, so there's no way to do a mapping
$this->assertEmpty($catalogue->getMetadata());
// target attributes
$this->assertEquals(array('target-attributes' => array('order' => 1)), $catalogue->getMetadata('bar', 'domain1'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
<group id="1">
<unit id="2">
<segment>
<source>An application to manipulate and process XLIFF documents</source>
<source>foo</source>
<target>XLIFF 文書を編集、または処理 するアプリケーションです。</target>
</segment>
</unit>
<unit id="3">
<segment>
<source>XLIFF Data Manager</source>
<target>XLIFF データ・マネージャ</target>
<source>bar</source>
<target order="1">XLIFF データ・マネージャ</target>
</segment>
</unit>
</group>
Expand Down
0