composer package updates
[openemr.git] / vendor / symfony / translation / Loader / IcuDatFileLoader.php
blob71ba90a39d9cc118f6ee9622029632b193c35eff
1 <?php
3 /*
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\MessageCatalogue;
15 use Symfony\Component\Translation\Exception\InvalidResourceException;
16 use Symfony\Component\Translation\Exception\NotFoundResourceException;
17 use Symfony\Component\Config\Resource\FileResource;
19 /**
20 * IcuResFileLoader loads translations from a resource bundle.
22 * @author stealth35
24 class IcuDatFileLoader extends IcuResFileLoader
26 /**
27 * {@inheritdoc}
29 public function load($resource, $locale, $domain = 'messages')
31 if (!stream_is_local($resource.'.dat')) {
32 throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
35 if (!file_exists($resource.'.dat')) {
36 throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
39 try {
40 $rb = new \ResourceBundle($locale, $resource);
41 } catch (\Exception $e) {
42 // HHVM compatibility: constructor throws on invalid resource
43 $rb = null;
46 if (!$rb) {
47 throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
48 } elseif (intl_is_failure($rb->getErrorCode())) {
49 throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
52 $messages = $this->flatten($rb);
53 $catalogue = new MessageCatalogue($locale);
54 $catalogue->add($messages, $domain);
56 if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
57 $catalogue->addResource(new FileResource($resource.'.dat'));
60 return $catalogue;