You are here

public function CsvFileLoader::load in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/translation/Loader/CsvFileLoader.php \Symfony\Component\Translation\Loader\CsvFileLoader::load()

Loads a locale.

Parameters

mixed $resource A resource:

string $locale A locale:

string $domain The domain:

Return value

MessageCatalogue A MessageCatalogue instance

Throws

NotFoundResourceException when the resource cannot be found

InvalidResourceException when the resource cannot be loaded

Overrides ArrayLoader::load

File

vendor/symfony/translation/Loader/CsvFileLoader.php, line 32

Class

CsvFileLoader
CsvFileLoader loads translations from CSV files.

Namespace

Symfony\Component\Translation\Loader

Code

public function load($resource, $locale, $domain = 'messages') {
  if (!stream_is_local($resource)) {
    throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
  }
  if (!file_exists($resource)) {
    throw new NotFoundResourceException(sprintf('File "%s" not found.', $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) && isset($data[1]) && 2 === count($data)) {
      $messages[$data[0]] = $data[1];
    }
  }
  $catalogue = parent::load($messages, $locale, $domain);
  if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
    $catalogue
      ->addResource(new FileResource($resource));
  }
  return $catalogue;
}