SymfonyComponentTranslationLoaderQtFileLoader

QtFileLoader loads translations from QT Translations XML files.

Defined (1)

The class is defined in the following location(s).

/vendor/symfony/translation/Loader/QtFileLoader.php  
  1. class QtFileLoader implements LoaderInterface 
  2. /** 
  3. * {@inheritdoc} 
  4. */ 
  5. public function load($resource, $locale, $domain = 'messages') 
  6. if (!stream_is_local($resource)) { 
  7. throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); 
  8.  
  9. if (!file_exists($resource)) { 
  10. throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); 
  11.  
  12. try { 
  13. $dom = XmlUtils::loadFile($resource); 
  14. } catch (\InvalidArgumentException $e) { 
  15. throw new InvalidResourceException(sprintf('Unable to load "%s".', $resource), $e->getCode(), $e); 
  16.  
  17. $internalErrors = libxml_use_internal_errors(true); 
  18. libxml_clear_errors(); 
  19.  
  20. $xpath = new \DOMXPath($dom); 
  21. $nodes = $xpath->evaluate('//TS/context/name[text()="'.$domain.'"]'); 
  22.  
  23. $catalogue = new MessageCatalogue($locale); 
  24. if ($nodes->length == 1) { 
  25. $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message'); 
  26. foreach ($translations as $translation) { 
  27. $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue; 
  28.  
  29. if (!empty($translationValue)) { 
  30. $catalogue->set( 
  31. (string) $translation->getElementsByTagName('source')->item(0)->nodeValue,  
  32. $translationValue,  
  33. $domain 
  34. ); 
  35. $translation = $translation->nextSibling; 
  36.  
  37. if (class_exists('Symfony\Component\Config\Resource\FileResource')) { 
  38. $catalogue->addResource(new FileResource($resource)); 
  39.  
  40. libxml_use_internal_errors($internalErrors); 
  41.  
  42. return $catalogue;