| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Loader; |
| 13 |
|
| 14 |
use Symfony\Component\Config\Resource\FileResource; |
| 15 |
use Symfony\Component\Translation\Exception\InvalidResourceException; |
| 16 |
use Symfony\Component\Translation\Exception\NotFoundResourceException; |
| 17 |
use Symfony\Component\Translation\MessageCatalogue; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class IcuDatFileLoader extends IcuResFileLoader |
| 25 |
{ |
| 26 |
public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue |
| 27 |
{ |
| 28 |
if (!stream_is_local($resource.'.dat')) { |
| 29 |
throw new InvalidResourceException(\sprintf('This is not a local file "%s".', $resource)); |
| 30 |
} |
| 31 |
|
| 32 |
if (!file_exists($resource.'.dat')) { |
| 33 |
throw new NotFoundResourceException(\sprintf('File "%s" not found.', $resource)); |
| 34 |
} |
| 35 |
|
| 36 |
try { |
| 37 |
$rb = new \ResourceBundle($locale, $resource); |
| 38 |
} catch (\Exception) { |
| 39 |
$rb = null; |
| 40 |
} |
| 41 |
|
| 42 |
if (!$rb) { |
| 43 |
throw new InvalidResourceException(\sprintf('Cannot load resource "%s".', $resource)); |
| 44 |
} elseif (intl_is_failure($rb->getErrorCode())) { |
| 45 |
throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode()); |
| 46 |
} |
| 47 |
|
| 48 |
$messages = $this->flatten($rb); |
| 49 |
$catalogue = new MessageCatalogue($locale); |
| 50 |
$catalogue->add($messages, $domain); |
| 51 |
|
| 52 |
if (class_exists(FileResource::class)) { |
| 53 |
$catalogue->addResource(new FileResource($resource.'.dat')); |
| 54 |
} |
| 55 |
|
| 56 |
return $catalogue; |
| 57 |
} |
| 58 |
} |