Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support omitting the <target> node in an .xlf file. #15604

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/Symfony/Component/Translation/Loader/XliffFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function load($resource, $locale, $domain = 'messages')
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
$attributes = $translation->attributes();

if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
if (!(isset($attributes['resname']) || isset($translation->source))) {
Copy link
Member

Choose a reason for hiding this comment

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

why do we also skip when resname is not set? It's an optional attribute according to the specs (unrelated to this PR, was just wondering)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only continue if there is neither a resname attribute nor a source string, which is ok.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, now I understand. Shouldn't this then be changed to !isset($attributes['resname']) && !isset($translation->source)? (which is a bit easier to read/understand)

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course this could be changed. We simply left it as it is to keep the PR as small as possible.
Depends on the reader which one is more easy to read anyway. ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wouterj I also prefer your way of writing it :)

continue;
}

$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
// 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) $translation->target, $encoding);
$target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public function testIncompleteResource()
$loader = new XliffFileLoader();
$catalogue = $loader->load(__DIR__.'/../fixtures/resources.xlf', 'en', 'domain1');

$this->assertEquals(array('foo' => 'bar', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
$this->assertFalse($catalogue->has('extra', 'domain1'));
$this->assertEquals(array('foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'), $catalogue->all('domain1'));
}

public function testEncoding()
Expand Down Expand Up @@ -136,7 +135,8 @@ public function testLoadNotes()

$this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo'))), $catalogue->getMetadata('foo', 'domain1'));
// message without target
$this->assertNull($catalogue->getMetadata('extra', 'domain1'));
$this->assertEquals(array('notes' => array(array('content' => 'bar', 'from' => 'foo'))), $catalogue->getMetadata('extra', 'domain1'));
// message with empty target
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux'))), $catalogue->getMetadata('key', 'domain1'));
}
}