You are here

public function JsonFileLoader::load in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/translation/Loader/JsonFileLoader.php \Symfony\Component\Translation\Loader\JsonFileLoader::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/JsonFileLoader.php, line 28

Class

JsonFileLoader
JsonFileLoader loads translations from an json file.

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();
  if ($data = file_get_contents($resource)) {
    $messages = json_decode($data, true);
    if (0 < ($errorCode = json_last_error())) {
      throw new InvalidResourceException(sprintf('Error parsing JSON - %s', $this
        ->getJSONErrorMessage($errorCode)));
    }
  }
  if (null === $messages) {
    $messages = array();
  }
  $catalogue = parent::load($messages, $locale, $domain);
  $catalogue
    ->addResource(new FileResource($resource));
  return $catalogue;
}