SymfonyComponentTranslationLoaderCsvFileLoader

CsvFileLoader loads translations from CSV files.

Defined (1)

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

/vendor/symfony/translation/Loader/CsvFileLoader.php  
  1. class CsvFileLoader extends FileLoader 
  2. private $delimiter = ';'; 
  3. private $enclosure = '"'; 
  4. private $escape = '\\'; 
  5.  
  6. /** 
  7. * {@inheritdoc} 
  8. */ 
  9. protected function loadResource($resource) 
  10. $messages = array(); 
  11.  
  12. try { 
  13. $file = new \SplFileObject($resource, 'rb'); 
  14. } catch (\RuntimeException $e) { 
  15. throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e); 
  16.  
  17. $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY); 
  18. $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape); 
  19.  
  20. foreach ($file as $data) { 
  21. if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === count($data)) { 
  22. $messages[$data[0]] = $data[1]; 
  23.  
  24. return $messages; 
  25.  
  26. /** 
  27. * Sets the delimiter, enclosure, and escape character for CSV. 
  28. * @param string $delimiter delimiter character 
  29. * @param string $enclosure enclosure character 
  30. * @param string $escape escape character 
  31. */ 
  32. public function setCsvControl($delimiter = ';', $enclosure = '"', $escape = '\\') 
  33. $this->delimiter = $delimiter; 
  34. $this->enclosure = $enclosure; 
  35. $this->escape = $escape;