From ad4adca53ad230c418784783c929009364e9eb91 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Thu, 12 May 2016 14:21:11 +0200 Subject: [PATCH] [Translation] XLIFF Add uid=501(fabien) gid=20(staff) groups=20(staff),401(com.apple.sharepoint.group.1),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),395(com.apple.access_ftp),398(com.apple.access_screensharing),399(com.apple.access_ssh) to meta data. --- .../Component/Translation/Loader/XliffFileLoader.php | 9 ++++++++- .../Translation/Tests/Loader/XliffFileLoaderTest.php | 8 ++++---- .../Component/Translation/Tests/fixtures/withnote.xlf | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php index bdca11099d..9c13e2df87 100644 --- a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php @@ -98,6 +98,7 @@ class XliffFileLoader implements LoaderInterface if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) { $metadata['notes'] = $notes; } + if (isset($translation->target) && $translation->target->attributes()) { $metadata['target-attributes'] = array(); foreach ($translation->target->attributes() as $key => $value) { @@ -105,6 +106,10 @@ class XliffFileLoader implements LoaderInterface } } + if (isset($attributes['id'])) { + $metadata['id'] = (string) $attributes['id']; + } + $catalogue->setMetadata((string) $source, $metadata, $domain); } } @@ -214,6 +219,7 @@ class XliffFileLoader implements LoaderInterface $parts = explode('/', str_replace('\\', '/', $tmpfile)); } } + $drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : ''; $newPath = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts)); @@ -280,7 +286,7 @@ class XliffFileLoader implements LoaderInterface return '1.2'; } - /* + /** * @param \SimpleXMLElement|null $noteElement * @param string|null $encoding * @@ -294,6 +300,7 @@ class XliffFileLoader implements LoaderInterface return $notes; } + /** @var \SimpleXMLElement $xmlNote */ foreach ($noteElement as $xmlNote) { $noteAttributes = $xmlNote->attributes(); $note = array('content' => $this->utf8ToCharset((string) $xmlNote, $encoding)); diff --git a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php index 9aafa4b161..5df3ceeea4 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php @@ -69,7 +69,7 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1')); $this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1')); - $this->assertEquals(array('notes' => array(array('content' => utf8_decode('bäz')))), $catalogue->getMetadata('foo', 'domain1')); + $this->assertEquals(array('notes' => array(array('content' => utf8_decode('bäz'))), 'id' => '1'), $catalogue->getMetadata('foo', 'domain1')); } public function testTargetAttributesAreStoredCorrectly() @@ -142,11 +142,11 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase $loader = new XliffFileLoader(); $catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1'); - $this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo'))), $catalogue->getMetadata('foo', 'domain1')); + $this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo')), 'id' => '1'), $catalogue->getMetadata('foo', 'domain1')); // message without target - $this->assertEquals(array('notes' => array(array('content' => 'bar', 'from' => 'foo'))), $catalogue->getMetadata('extra', 'domain1')); + $this->assertEquals(array('notes' => array(array('content' => 'bar', 'from' => 'foo')), 'id' => '2'), $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')); + $this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux')), 'id' => '123'), $catalogue->getMetadata('key', 'domain1')); } public function testLoadVersion2() diff --git a/src/Symfony/Component/Translation/Tests/fixtures/withnote.xlf b/src/Symfony/Component/Translation/Tests/fixtures/withnote.xlf index b1d3f83a0c..c045e21e23 100644 --- a/src/Symfony/Component/Translation/Tests/fixtures/withnote.xlf +++ b/src/Symfony/Component/Translation/Tests/fixtures/withnote.xlf @@ -11,7 +11,7 @@ extra bar - + key baz