aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/translation/Symfony/Component/Translation/Loader/IcuDatFileLoader.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/translation/Symfony/Component/Translation/Loader/IcuDatFileLoader.php')
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Loader/IcuDatFileLoader.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Loader/IcuDatFileLoader.php b/vendor/symfony/translation/Symfony/Component/Translation/Loader/IcuDatFileLoader.php
new file mode 100644
index 00000000..104883b0
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Loader/IcuDatFileLoader.php
@@ -0,0 +1,54 @@
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
12namespace Symfony\Component\Translation\Loader;
13
14use Symfony\Component\Translation\MessageCatalogue;
15use Symfony\Component\Translation\Exception\InvalidResourceException;
16use Symfony\Component\Translation\Exception\NotFoundResourceException;
17use Symfony\Component\Config\Resource\FileResource;
18
19/**
20 * IcuResFileLoader loads translations from a resource bundle.
21 *
22 * @author stealth35
23 */
24class IcuDatFileLoader extends IcuResFileLoader
25{
26 /**
27 * {@inheritdoc}
28 */
29 public function load($resource, $locale, $domain = 'messages')
30 {
31 if (!stream_is_local($resource.'.dat')) {
32 throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
33 }
34
35 if (!file_exists($resource.'.dat')) {
36 throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
37 }
38
39 $rb = new \ResourceBundle($locale, $resource);
40
41 if (!$rb) {
42 throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
43 } elseif (intl_is_failure($rb->getErrorCode())) {
44 throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
45 }
46
47 $messages = $this->flatten($rb);
48 $catalogue = new MessageCatalogue($locale);
49 $catalogue->add($messages, $domain);
50 $catalogue->addResource(new FileResource($resource.'.dat'));
51
52 return $catalogue;
53 }
54}