ArrayLoader.php
1 month ago
CsvFileLoader.php
1 month ago
FileLoader.php
1 month ago
IcuDatFileLoader.php
1 month ago
IcuResFileLoader.php
1 month ago
IniFileLoader.php
1 month ago
JsonFileLoader.php
1 month ago
LoaderInterface.php
1 month ago
MoFileLoader.php
1 month ago
PhpFileLoader.php
1 month ago
PoFileLoader.php
1 month ago
QtFileLoader.php
1 month ago
XliffFileLoader.php
1 month ago
YamlFileLoader.php
1 month ago
IcuDatFileLoader.php
55 lines
| 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 | namespace IAWPSCOPED\Symfony\Component\Translation\Loader; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\Config\Resource\FileResource; |
| 14 | use IAWPSCOPED\Symfony\Component\Translation\Exception\InvalidResourceException; |
| 15 | use IAWPSCOPED\Symfony\Component\Translation\Exception\NotFoundResourceException; |
| 16 | use IAWPSCOPED\Symfony\Component\Translation\MessageCatalogue; |
| 17 | /** |
| 18 | * IcuResFileLoader loads translations from a resource bundle. |
| 19 | * |
| 20 | * @author stealth35 |
| 21 | * @internal |
| 22 | */ |
| 23 | class IcuDatFileLoader extends IcuResFileLoader |
| 24 | { |
| 25 | /** |
| 26 | * {@inheritdoc} |
| 27 | */ |
| 28 | public function load(mixed $resource, string $locale, string $domain = 'messages') : MessageCatalogue |
| 29 | { |
| 30 | if (!\stream_is_local($resource . '.dat')) { |
| 31 | throw new InvalidResourceException(\sprintf('This is not a local file "%s".', $resource)); |
| 32 | } |
| 33 | if (!\file_exists($resource . '.dat')) { |
| 34 | throw new NotFoundResourceException(\sprintf('File "%s" not found.', $resource)); |
| 35 | } |
| 36 | try { |
| 37 | $rb = new \ResourceBundle($locale, $resource); |
| 38 | } catch (\Exception $e) { |
| 39 | $rb = null; |
| 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 | $messages = $this->flatten($rb); |
| 47 | $catalogue = new MessageCatalogue($locale); |
| 48 | $catalogue->add($messages, $domain); |
| 49 | if (\class_exists(FileResource::class)) { |
| 50 | $catalogue->addResource(new FileResource($resource . '.dat')); |
| 51 | } |
| 52 | return $catalogue; |
| 53 | } |
| 54 | } |
| 55 |