PluginProbe
Independent Analytics – WordPress Analytics Plugin / 1.28.0
Independent Analytics – WordPress Analytics Plugin v1.28.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / vendor / symfony / translation / Loader / QtFileLoader.php
QtFileLoader.php
67 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace IAWP_SCOPED\Symfony\Component\Translation\Loader;
12
13 use IAWP_SCOPED\Symfony\Component\Config\Resource\FileResource;
14 use IAWP_SCOPED\Symfony\Component\Config\Util\XmlUtils;
15 use IAWP_SCOPED\Symfony\Component\Translation\Exception\InvalidResourceException;
16 use IAWP_SCOPED\Symfony\Component\Translation\Exception\NotFoundResourceException;
17 use IAWP_SCOPED\Symfony\Component\Translation\Exception\RuntimeException;
18 use IAWP_SCOPED\Symfony\Component\Translation\MessageCatalogue;
19 /**
20 * QtFileLoader loads translations from QT Translations XML files.
21 *
22 * @author Benjamin Eberlei <kontakt@beberlei.de>
23 */
24 class QtFileLoader implements LoaderInterface
25 {
26 /**
27 * {@inheritdoc}
28 */
29 public function load($resource, string $locale, string $domain = 'messages')
30 {
31 if (!\class_exists(XmlUtils::class)) {
32 throw new RuntimeException('Loading translations from the QT format requires the Symfony Config component.');
33 }
34 if (!\stream_is_local($resource)) {
35 throw new InvalidResourceException(\sprintf('This is not a local file "%s".', $resource));
36 }
37 if (!\file_exists($resource)) {
38 throw new NotFoundResourceException(\sprintf('File "%s" not found.', $resource));
39 }
40 try {
41 $dom = XmlUtils::loadFile($resource);
42 } catch (\InvalidArgumentException $e) {
43 throw new InvalidResourceException(\sprintf('Unable to load "%s".', $resource), $e->getCode(), $e);
44 }
45 $internalErrors = \libxml_use_internal_errors(\true);
46 \libxml_clear_errors();
47 $xpath = new \DOMXPath($dom);
48 $nodes = $xpath->evaluate('//TS/context/name[text()="' . $domain . '"]');
49 $catalogue = new MessageCatalogue($locale);
50 if (1 == $nodes->length) {
51 $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message');
52 foreach ($translations as $translation) {
53 $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue;
54 if (!empty($translationValue)) {
55 $catalogue->set((string) $translation->getElementsByTagName('source')->item(0)->nodeValue, $translationValue, $domain);
56 }
57 $translation = $translation->nextSibling;
58 }
59 if (\class_exists(FileResource::class)) {
60 $catalogue->addResource(new FileResource($resource));
61 }
62 }
63 \libxml_use_internal_errors($internalErrors);
64 return $catalogue;
65 }
66 }
67