feature #18762 [Translation] XLIFF Add id
to meta data. (SpacePossum)
This PR was squashed before being merged into the 3.1-dev branch (closes #18762).
Discussion
----------
[Translation] XLIFF Add `id` to meta data.
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | maybe/no
| Deprecations? | no
| Tests pass? | yes
| License | MIT
I would like to get the `id` attribute value from parsed XLIFF v1.2 files in the meta data (of the catalogue).
Commits
-------
ad4adca
[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.
This commit is contained in:
commit
3d93a961f4
@ -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));
|
||||
|
@ -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()
|
||||
|
@ -11,7 +11,7 @@
|
||||
<source>extra</source>
|
||||
<note from="foo">bar</note>
|
||||
</trans-unit>
|
||||
<trans-unit id="3">
|
||||
<trans-unit id="123">
|
||||
<source>key</source>
|
||||
<target></target>
|
||||
<note>baz</note>
|
||||
|
Reference in New Issue
Block a user