8000 [XLIFF 2.0] added support for target attributes. · symfony/symfony@7af4fc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7af4fc7

Browse files
committed
[XLIFF 2.0] added support for target attributes.
1 parent ace6042 commit 7af4fc7

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $
103103
$metadata['notes'] = $notes;
104104
}
105105
if (isset($translation->target) && $translation->target->attributes()) {
106-
$metadata['target-attributes'] = $translation->target->attributes();
106+
$metadata['target-attributes'] = array();
107+
foreach ($translation->target->attributes() as $key => $value) {
108+
$metadata['target-attributes'][$key] = (string) $value;
109+
}
107110
}
108111

109112
$catalogue->setMetadata((string) $source, $metadata, $domain);
@@ -127,9 +130,19 @@ private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, $
127130

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

132135
$catalogue->set((string) $source, $target, $domain);
136+
137+
$metadata = array();
138+
if (isset($segment->target) && $segment->target->attributes()) {
139+
$metadata['target-attributes'] = array();
140+
foreach ($segment->target->attributes() as $key => $value) {
141+
$metadata['target-attributes'][$key] = (string) $value;
142+
}
143+
}
144+
145+
$catalogue->setMetadata((string) $source, $metadata, $domain);
133146
}
134147
}
135148

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function testLoadVersion2()
164164
$this->assertCount(3, $domains['domain1']);
165165
$this->assertContainsOnly('string', $catalogue->all('domain1'));
166166

167-
// Notes aren't assigned to specific segments, but to whole units, so there's no way to do a mapping
168-
$this->assertEmpty($catalogue->getMetadata());
167+
// target attributes
168+
$this->assertEquals(array('target-attributes' => array('order' => 1)), $catalogue->getMetadata('bar', 'domain1'));
169169
}
170170
}

src/Symfony/Component/Translation/Tests/fixtures/resources-2.0.xlf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
<group id="1">
1111
<unit id="2">
1212
<segment>
13-
<source>An application to manipulate and process XLIFF documents</source>
13+
<source>foo</source>
1414
<target>XLIFF 文書を編集、または処理 するアプリケーションです。</target>
1515
</segment>
1616
</unit>
1717
<unit id="3">
1818
<segment>
19-
<source>XLIFF Data Manager</source>
20-
<target>XLIFF データ・マネージャ</target>
19+
<source>bar</source>
20+
<target order="1">XLIFF データ・マネージャ</target>
2121
</segment>
2222
</unit>
2323
</group>

0 commit comments

Comments
 (0)
0