1 | <?php |
||
23 | class SymfonyPort |
||
24 | { |
||
25 | /** |
||
26 | * @param \DOMDocument $dom |
||
27 | * @param MessageCatalogue $catalogue |
||
28 | * @param string $domain |
||
29 | */ |
||
30 | 3 | public function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, $domain) |
|
31 | { |
||
32 | 3 | $xml = simplexml_import_dom($dom); |
|
33 | 3 | $encoding = strtoupper($dom->encoding); |
|
34 | |||
35 | 3 | $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0'); |
|
36 | |||
37 | 3 | foreach ($xml->xpath('//xliff:unit') as $unit) { |
|
38 | 3 | $segment = $unit->segment; |
|
39 | 3 | $source = $segment->source; |
|
40 | |||
41 | // If the xlf file has another encoding specified, try to convert it because |
||
42 | // simple_xml will always return utf-8 encoded values |
||
43 | 3 | $target = $this->utf8ToCharset((string) (isset($segment->target) ? $segment->target : $source), $encoding); |
|
44 | |||
45 | 3 | $catalogue->set((string) $source, $target, $domain); |
|
46 | |||
47 | 3 | $metadata = []; |
|
48 | 3 | if (isset($segment->target) && $segment->target->attributes()) { |
|
49 | $metadata['target-attributes'] = []; |
||
50 | foreach ($segment->target->attributes() as $key => $value) { |
||
51 | $metadata['target-attributes'][$key] = (string) $value; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | 3 | if (isset($unit->notes)) { |
|
56 | 2 | $metadata['notes'] = []; |
|
57 | 2 | foreach ($unit->notes->note as $noteNode) { |
|
58 | 2 | $note = []; |
|
59 | 2 | foreach ($noteNode->attributes() as $key => $value) { |
|
60 | 2 | $note[$key] = (string) $value; |
|
61 | } |
||
62 | 2 | $note['content'] = (string) $noteNode; |
|
63 | 2 | $metadata['notes'][] = $note; |
|
64 | } |
||
65 | } |
||
66 | |||
67 | 3 | $catalogue->setMetadata((string) $source, $metadata, $domain); |
|
68 | } |
||
69 | 3 | } |
|
70 | |||
71 | /** |
||
72 | * Convert a UTF8 string to the specified encoding. |
||
73 | * |
||
74 | * @param string $content String to decode |
||
75 | * @param string $encoding Target encoding |
||
76 | * |
||
77 | * @return string |
||
78 | */ |
||
79 | 3 | private function utf8ToCharset($content, $encoding = null) |
|
87 | |||
88 | /** |
||
89 | * Gets xliff file version based on the root "version" attribute. |
||
90 | * Defaults to 1.2 for backwards compatibility. |
||
91 | * |
||
92 | * @param \DOMDocument $dom |
||
93 | * |
||
94 | * @throws InvalidArgumentException |
||
95 | * |
||
96 | * @return string |
||
97 | * |
||
98 | * @deprecated Will be removed when we drop support for SF2.7 |
||
99 | */ |
||
100 | public function getVersionNumber(\DOMDocument $dom) |
||
122 | |||
123 | /** |
||
124 | * Extract messages and metadata from DOMDocument into a MessageCatalogue. |
||
125 | * |
||
126 | * @param \DOMDocument $dom Source to extract messages and metadata |
||
127 | * @param MessageCatalogue $catalogue Catalogue where we'll collect messages and metadata |
||
128 | * @param string $domain The domain |
||
129 | * |
||
130 | * @deprecated Will be removed when we drop support for SF2.7 |
||
131 | */ |
||
132 | public function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $domain) |
||
171 | |||
172 | /** |
||
173 | * @param \SimpleXMLElement|null $noteElement |
||
174 | * @param string|null $encoding |
||
175 | * |
||
176 | * @return array |
||
177 | * |
||
178 | * @deprecated Will be removed when we drop support for SF2.7 |
||
179 | */ |
||
180 | private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, $encoding = null) |
||
205 | } |
||
206 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.