4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Loader
;
14 use Symfony\Component\Translation\Exception\InvalidResourceException
;
15 use Symfony\Component\Translation\Exception\NotFoundResourceException
;
16 use Symfony\Component\Config\
Resource\FileResource
;
17 use Symfony\Component\Yaml\Parser
as YamlParser
;
18 use Symfony\Component\Yaml\Exception\ParseException
;
21 * YamlFileLoader loads translations from Yaml files.
23 * @author Fabien Potencier <fabien@symfony.com>
27 class YamlFileLoader
extends ArrayLoader
implements LoaderInterface
36 public function load($resource, $locale, $domain = 'messages')
38 if (!stream_is_local($resource)) {
39 throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
42 if (!file_exists($resource)) {
43 throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
46 if (null === $this->yamlParser
) {
47 $this->yamlParser
= new YamlParser();
51 $messages = $this->yamlParser
->parse(file_get_contents($resource));
52 } catch (ParseException
$e) {
53 throw new InvalidResourceException('Error parsing YAML.', 0, $e);
57 if (null === $messages) {
62 if (!is_array($messages)) {
63 throw new InvalidResourceException(sprintf('The file "%s" must contain a YAML array.', $resource));
66 $catalogue = parent
::load($messages, $locale, $domain);
67 $catalogue->addResource(new FileResource($resource));