Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/translation/Loader/XliffFileLoader.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
9 * file that was distributed with this source code. | 9 * file that was distributed with this source code. |
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\Translation\Loader; | 12 namespace Symfony\Component\Translation\Loader; |
13 | 13 |
14 use Symfony\Component\Config\Resource\FileResource; | |
14 use Symfony\Component\Config\Util\XmlUtils; | 15 use Symfony\Component\Config\Util\XmlUtils; |
15 use Symfony\Component\Translation\MessageCatalogue; | 16 use Symfony\Component\Translation\Exception\InvalidArgumentException; |
16 use Symfony\Component\Translation\Exception\InvalidResourceException; | 17 use Symfony\Component\Translation\Exception\InvalidResourceException; |
17 use Symfony\Component\Translation\Exception\NotFoundResourceException; | 18 use Symfony\Component\Translation\Exception\NotFoundResourceException; |
18 use Symfony\Component\Translation\Exception\InvalidArgumentException; | 19 use Symfony\Component\Translation\MessageCatalogue; |
19 use Symfony\Component\Config\Resource\FileResource; | |
20 | 20 |
21 /** | 21 /** |
22 * XliffFileLoader loads translations from XLIFF files. | 22 * XliffFileLoader loads translations from XLIFF files. |
23 * | 23 * |
24 * @author Fabien Potencier <fabien@symfony.com> | 24 * @author Fabien Potencier <fabien@symfony.com> |
89 } | 89 } |
90 | 90 |
91 $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source; | 91 $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source; |
92 // If the xlf file has another encoding specified, try to convert it because | 92 // If the xlf file has another encoding specified, try to convert it because |
93 // simple_xml will always return utf-8 encoded values | 93 // simple_xml will always return utf-8 encoded values |
94 $target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding); | 94 $target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $translation->source), $encoding); |
95 | 95 |
96 $catalogue->set((string) $source, $target, $domain); | 96 $catalogue->set((string) $source, $target, $domain); |
97 | 97 |
98 $metadata = array(); | 98 $metadata = []; |
99 if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) { | 99 if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) { |
100 $metadata['notes'] = $notes; | 100 $metadata['notes'] = $notes; |
101 } | 101 } |
102 | 102 |
103 if (isset($translation->target) && $translation->target->attributes()) { | 103 if (isset($translation->target) && $translation->target->attributes()) { |
104 $metadata['target-attributes'] = array(); | 104 $metadata['target-attributes'] = []; |
105 foreach ($translation->target->attributes() as $key => $value) { | 105 foreach ($translation->target->attributes() as $key => $value) { |
106 $metadata['target-attributes'][$key] = (string) $value; | 106 $metadata['target-attributes'][$key] = (string) $value; |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
135 // simple_xml will always return utf-8 encoded values | 135 // simple_xml will always return utf-8 encoded values |
136 $target = $this->utf8ToCharset((string) (isset($segment->target) ? $segment->target : $source), $encoding); | 136 $target = $this->utf8ToCharset((string) (isset($segment->target) ? $segment->target : $source), $encoding); |
137 | 137 |
138 $catalogue->set((string) $source, $target, $domain); | 138 $catalogue->set((string) $source, $target, $domain); |
139 | 139 |
140 $metadata = array(); | 140 $metadata = []; |
141 if (isset($segment->target) && $segment->target->attributes()) { | 141 if (isset($segment->target) && $segment->target->attributes()) { |
142 $metadata['target-attributes'] = array(); | 142 $metadata['target-attributes'] = []; |
143 foreach ($segment->target->attributes() as $key => $value) { | 143 foreach ($segment->target->attributes() as $key => $value) { |
144 $metadata['target-attributes'][$key] = (string) $value; | 144 $metadata['target-attributes'][$key] = (string) $value; |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 if (isset($unit->notes)) { | 148 if (isset($unit->notes)) { |
149 $metadata['notes'] = array(); | 149 $metadata['notes'] = []; |
150 foreach ($unit->notes->note as $noteNode) { | 150 foreach ($unit->notes->note as $noteNode) { |
151 $note = array(); | 151 $note = []; |
152 foreach ($noteNode->attributes() as $key => $value) { | 152 foreach ($noteNode->attributes() as $key => $value) { |
153 $note[$key] = (string) $value; | 153 $note[$key] = (string) $value; |
154 } | 154 } |
155 $note['content'] = (string) $noteNode; | 155 $note['content'] = (string) $noteNode; |
156 $metadata['notes'][] = $note; | 156 $metadata['notes'][] = $note; |
245 array_shift($parts); | 245 array_shift($parts); |
246 $locationstart = 'phar:///'; | 246 $locationstart = 'phar:///'; |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 $drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : ''; | 250 $drive = '\\' === \DIRECTORY_SEPARATOR ? array_shift($parts).'/' : ''; |
251 $newPath = $locationstart.$drive.implode('/', array_map('rawurlencode', $parts)); | 251 $newPath = $locationstart.$drive.implode('/', array_map('rawurlencode', $parts)); |
252 | 252 |
253 return str_replace($xmlUri, $newPath, $schemaSource); | 253 return str_replace($xmlUri, $newPath, $schemaSource); |
254 } | 254 } |
255 | 255 |
260 * | 260 * |
261 * @return array An array of errors | 261 * @return array An array of errors |
262 */ | 262 */ |
263 private function getXmlErrors($internalErrors) | 263 private function getXmlErrors($internalErrors) |
264 { | 264 { |
265 $errors = array(); | 265 $errors = []; |
266 foreach (libxml_get_errors() as $error) { | 266 foreach (libxml_get_errors() as $error) { |
267 $errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)', | 267 $errors[] = sprintf('[%s %s] %s (in %s - line %d, column %d)', |
268 LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR', | 268 LIBXML_ERR_WARNING == $error->level ? 'WARNING' : 'ERROR', |
269 $error->code, | 269 $error->code, |
270 trim($error->message), | 270 trim($error->message), |
319 * | 319 * |
320 * @return array | 320 * @return array |
321 */ | 321 */ |
322 private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, $encoding = null) | 322 private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, $encoding = null) |
323 { | 323 { |
324 $notes = array(); | 324 $notes = []; |
325 | 325 |
326 if (null === $noteElement) { | 326 if (null === $noteElement) { |
327 return $notes; | 327 return $notes; |
328 } | 328 } |
329 | 329 |
330 /** @var \SimpleXMLElement $xmlNote */ | 330 /** @var \SimpleXMLElement $xmlNote */ |
331 foreach ($noteElement as $xmlNote) { | 331 foreach ($noteElement as $xmlNote) { |
332 $noteAttributes = $xmlNote->attributes(); | 332 $noteAttributes = $xmlNote->attributes(); |
333 $note = array('content' => $this->utf8ToCharset((string) $xmlNote, $encoding)); | 333 $note = ['content' => $this->utf8ToCharset((string) $xmlNote, $encoding)]; |
334 if (isset($noteAttributes['priority'])) { | 334 if (isset($noteAttributes['priority'])) { |
335 $note['priority'] = (int) $noteAttributes['priority']; | 335 $note['priority'] = (int) $noteAttributes['priority']; |
336 } | 336 } |
337 | 337 |
338 if (isset($noteAttributes['from'])) { | 338 if (isset($noteAttributes['from'])) { |