You are here

protected function CsvFileLoader::loadResource in Plug 7

Overrides FileLoader::loadResource

File

lib/Symfony/translation/Loader/CsvFileLoader.php, line 32

Class

CsvFileLoader
CsvFileLoader loads translations from CSV files.

Namespace

Symfony\Component\Translation\Loader

Code

protected function loadResource($resource) {
  $messages = array();
  try {
    $file = new \SplFileObject($resource, 'rb');
  } catch (\RuntimeException $e) {
    throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
  }
  $file
    ->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
  $file
    ->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
  foreach ($file as $data) {
    if (substr($data[0], 0, 1) === '#') {
      continue;
    }
    if (!isset($data[1])) {
      continue;
    }
    if (count($data) == 2) {
      $messages[$data[0]] = $data[1];
    }
    else {
      continue;
    }
  }
  return $messages;
}