Skip to content

Commit e20a9b7

Browse files
Merge branch '3.4' into 4.0
* 3.4: [Translation] Process multiple segments within a single unit. Document the container.autowiring.strict_mode option fix custom radios/inputs for checkbox/radio type Another PR template tweak [FrameworkBundle] Add missing XML config for circular_reference_handler. Add tests. fix CS [PropertyInfo] ReflectionExtractor: give a chance to other extractors if no properties Clean calls to http_build_query() [WebProfilerBundle] limit ajax request to 100 and remove the last one Add support for URL-like DSNs for the PdoSessionHandler [HttpFoundation] Fix missing "throw" in JsonResponse Improve the documentation of Suppress warning from sapi_windows_vt100_support on stream other than STDIO removed extra-verbose comments Fixes #26136: Avoid emitting warning in hasParameterOption() Added a README entry to the PR template [HttpFoundation] Add x-zip-compressed to MimeTypeExtensionGuesser. [DI] Add null check for removeChild
2 parents 2a947a1 + 80e19ea commit e20a9b7

File tree

3 files changed

+69
-22
lines changed

3 files changed

+69
-22
lines changed

Loader/XliffFileLoader.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,36 +123,37 @@ private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, s
123123
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0');
124124

125125
foreach ($xml->xpath('//xliff:unit') as $unit) {
126-
$segment = $unit->segment;
127-
$source = $segment->source;
126+
foreach ($unit->segment as $segment) {
127+
$source = $segment->source;
128128

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

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

135-
$metadata = array();
136-
if (isset($segment->target) && $segment->target->attributes()) {
137-
$metadata['target-attributes'] = array();
138-
foreach ($segment->target->attributes() as $key => $value) {
139-
$metadata['target-attributes'][$key] = (string) $value;
135+
$metadata = array();
136+
if (isset($segment->target) && $segment->target->attributes()) {
137+
$metadata['target-attributes'] = array();
138+
foreach ($segment->target->attributes() as $key => $value) {
139+
$metadata['target-attributes'][$key] = (string) $value;
140+
}
140141
}
141-
}
142142

143-
if (isset($unit->notes)) {
144-
$metadata['notes'] = array();
145-
foreach ($unit->notes->note as $noteNode) {
146-
$note = array();
147-
foreach ($noteNode->attributes() as $key => $value) {
148-
$note[$key] = (string) $value;
143+
if (isset($unit->notes)) {
144+
$metadata['notes'] = array();
145+
foreach ($unit->notes->note as $noteNode) {
146+
$note = array();
147+
foreach ($noteNode->attributes() as $key => $value) {
148+
$note[$key] = (string) $value;
149+
}
150+
$note['content'] = (string) $noteNode;
151+
$metadata['notes'][] = $note;
149152
}
150-
$note['content'] = (string) $noteNode;
151-
$metadata['notes'][] = $note;
152153
}
153-
}
154154

155-
$catalogue->setMetadata((string) $source, $metadata, $domain);
155+
$catalogue->setMetadata((string) $source, $metadata, $domain);
156+
}
156157
}
157158
}
158159

Tests/Loader/XliffFileLoaderTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,33 @@ public function testLoadVersion2WithNoteMeta()
228228
$this->assertEquals('quality', $metadata['notes'][1]['category']);
229229
$this->assertEquals('Fuzzy', $metadata['notes'][1]['content']);
230230
}
231+
232+
public function testLoadVersion2WithMultiSegmentUnit()
233+
{
234+
$loader = new XliffFileLoader();
235+
$resource = __DIR__.'/../fixtures/resources-2.0-multi-segment-unit.xlf';
236+
$catalog = $loader->load($resource, 'en', 'domain1');
237+
238+
$this->assertSame('en', $catalog->getLocale());
239+
$this->assertEquals(array(new FileResource($resource)), $catalog->getResources());
240+
$this->assertFalse(libxml_get_last_error());
241+
242+
// test for "foo" metadata
243+
$this->assertTrue($catalog->defines('foo', 'domain1'));
244+
$metadata = $catalog->getMetadata('foo', 'domain1');
245+
$this->assertNotEmpty($metadata);
246+
$this->assertCount(1, $metadata['notes']);
247+
248+
$this->assertSame('processed', $metadata['notes'][0]['category']);
249+
$this->assertSame('true', $metadata['notes'][0]['content']);
250+
251+
// test for "bar" metadata
252+
$this->assertTrue($catalog->defines('bar', 'domain1'));
253+
$metadata = $catalog->getMetadata('bar', 'domain1');
254+
$this->assertNotEmpty($metadata);
255+
$this->assertCount(1, $metadata['notes']);
256+
257+
$this->assertSame('processed', $metadata['notes'][0]['category']);
258+
$this->assertSame('true', $metadata['notes'][0]['content']);
259+
}
231260
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US" trgLang="en-US">
2+
<file id="f1">
3+
<unit id="1">
4+
<notes>
5+
<note category="processed">true</note>
6+
</notes>
7+
<segment id="id-foo">
8+
<source>foo</source>
9+
<target>foo (translated)</target>
10+
</segment>
11+
<segment id="id-bar">
12+
<source>bar</source>
13+
<target>bar (translated)</target>
14+
</segment>
15+
</unit>
16+
</file>
17+
</xliff>

0 commit comments

Comments
 (0)