Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d93a96

Browse filesBrowse files
committed
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.
2 parents c86a1a1 + ad4adca commit 3d93a96
Copy full SHA for 3d93a96

File tree

3 files changed

+13
-6
lines changed
Filter options

3 files changed

+13
-6
lines changed

‎src/Symfony/Component/Translation/Loader/XliffFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Loader/XliffFileLoader.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $
9898
if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) {
9999
$metadata['notes'] = $notes;
100100
}
101+
101102
if (isset($translation->target) && $translation->target->attributes()) {
102103
$metadata['target-attributes'] = array();
103104
foreach ($translation->target->attributes() as $key => $value) {
104105
$metadata['target-attributes'][$key] = (string) $value;
105106
}
106107
}
107108

109+
if (isset($attributes['id'])) {
110+
$metadata['id'] = (string) $attributes['id'];
111+
}
112+
108113
$catalogue->setMetadata((string) $source, $metadata, $domain);
109114
}
110115
}
@@ -214,6 +219,7 @@ private function fixXmlLocation($schemaSource, $xmlUri)
214219
$parts = explode('/', str_replace('\\', '/', $tmpfile));
215220
}
216221
}
222+
217223
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
218224
$newPath = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));
219225

@@ -280,7 +286,7 @@ private function getVersionNumber(\DOMDocument $dom)
280286
return '1.2';
281287
}
282288

283-
/*
289+
/**
284290
* @param \SimpleXMLElement|null $noteElement
285291
* @param string|null $encoding
286292
*
@@ -294,6 +300,7 @@ private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, $enco
294300
return $notes;
295301
}
296302

303+
/** @var \SimpleXMLElement $xmlNote */
297304
foreach ($noteElement as $xmlNote) {
298305
$noteAttributes = $xmlNote->attributes();
299306
$note = array('content' => $this->utf8ToCharset((string) $xmlNote, $encoding));

‎src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testEncoding()
6969

7070
$this->assertEquals(utf8_decode('föö'), $catalogue->get('bar', 'domain1'));
7171
$this->assertEquals(utf8_decode('bär'), $catalogue->get('foo', 'domain1'));
72-
$this->assertEquals(array('notes' => array(array('content' => utf8_decode('bäz')))), $catalogue->getMetadata('foo', 'domain1'));
72+
$this->assertEquals(array('notes' => array(array('content' => utf8_decode('bäz'))), 'id' => '1'), $catalogue->getMetadata('foo', 'domain1'));
7373
}
7474

7575
public function testTargetAttributesAreStoredCorrectly()
@@ -142,11 +142,11 @@ public function testLoadNotes()
142142
$loader = new XliffFileLoader();
143143
$catalogue = $loader->load(__DIR__.'/../fixtures/withnote.xlf', 'en', 'domain1');
144144

145-
$this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo'))), $catalogue->getMetadata('foo', 'domain1'));
145+
$this->assertEquals(array('notes' => array(array('priority' => 1, 'content' => 'foo')), 'id' => '1'), $catalogue->getMetadata('foo', 'domain1'));
146146
// message without target
147-
$this->assertEquals(array('notes' => array(array('content' => 'bar', 'from' => 'foo'))), $catalogue->getMetadata('extra', 'domain1'));
147+
$this->assertEquals(array('notes' => array(array('content' => 'bar', 'from' => 'foo')), 'id' => '2'), $catalogue->getMetadata('extra', 'domain1'));
148148
// message with empty target
149-
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux'))), $catalogue->getMetadata('key', 'domain1'));
149+
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux')), 'id' => '123'), $catalogue->getMetadata('key', 'domain1'));
150150
}
151151

152152
public function testLoadVersion2()

‎src/Symfony/Component/Translation/Tests/fixtures/withnote.xlf

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/fixtures/withnote.xlf
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<source>extra</source>
1212
<note from="foo">bar</note>
1313
</trans-unit>
14-
<trans-unit id="3">
14+
<trans-unit id="123">
1515
<source>key</source>
1616
<target></target>
1717
<note>baz</note>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.