|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Translation\Loader; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Config\Resource\FileResource; |
|
|
15 |
use Symfony\Component\Yaml\Yaml; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* YamlFileLoader loads translations from Yaml files. |
|
|
19 |
* |
|
|
20 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
21 |
* |
|
|
22 |
* @api |
|
|
23 |
*/ |
|
|
24 |
class YamlFileLoader extends ArrayLoader implements LoaderInterface |
|
|
25 |
{ |
|
|
26 |
/** |
|
|
27 |
* {@inheritdoc} |
|
|
28 |
* |
|
|
29 |
* @api |
|
|
30 |
*/ |
|
|
31 |
public function load($resource, $locale, $domain = 'messages') |
|
|
32 |
{ |
|
|
33 |
$messages = Yaml::parse($resource); |
|
|
34 |
|
|
|
35 |
// empty file |
|
|
36 |
if (null === $messages) { |
|
|
37 |
$messages = array(); |
|
|
38 |
} |
|
|
39 |
|
|
|
40 |
// not an array |
|
|
41 |
if (!is_array($messages)) { |
|
|
42 |
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $resource)); |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
$catalogue = parent::load($messages, $locale, $domain); |
|
|
46 |
$catalogue->addResource(new FileResource($resource)); |
|
|
47 |
|
|
|
48 |
return $catalogue; |
|
|
49 |
} |
|
|
50 |
} |