* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Translation\Loader; use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\Translation\Exception\InvalidResourceException; use Symfony\Component\Translation\Exception\NotFoundResourceException; use Symfony\Component\Translation\MessageCatalogue; /** * IcuResFileLoader loads translations from a resource bundle. * * @author stealth35 */ class IcuResFileLoader implements LoaderInterface { public function load(mixed $resource, string $locale, string $domain = 'messages'): MessageCatalogue { if (!stream_is_local($resource)) { throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); } if (!is_dir($resource)) { throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); } try { $rb = new \ResourceBundle($locale, $resource); } catch (\Exception) { $rb = null; } if (!$rb) { throw new InvalidResourceException(sprintf('Cannot load resource "%s".', $resource)); } elseif (intl_is_failure($rb->getErrorCode())) { throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode()); } $messages = $this->flatten($rb); $catalogue = new MessageCatalogue($locale); $catalogue->add($messages, $domain); if (class_exists(DirectoryResource::class)) { $catalogue->addResource(new DirectoryResource($resource)); } return $catalogue; } /** * Flattens an ResourceBundle. * * The scheme used is: * key { key2 { key3 { "value" } } } * Becomes: * 'key.key2.key3' => 'value' * * This function takes an array by reference and will modify it * * @param \ResourceBundle $rb The ResourceBundle that will be flattened * @param array $messages Used internally for recursive calls * @param string $path Current path being parsed, used internally for recursive calls */ protected function flatten(\ResourceBundle $rb, array &$messages = [], string $path = null): array { foreach ($rb as $key => $value) { $nodePath = $path ? $path.'.'.$key : $key; if ($value instanceof \ResourceBundle) { $this->flatten($value, $messages, $nodePath); } else { $messages[$nodePath] = $value; } } return $messages; } } __halt_compiler();----SIGNATURE:----Z6ElFAjnI6hjeZ8QegbpGfTfR/CEUu8/Kt0g2OQ6fhAz4G93an8ZLddCuINWdNGXhrw/sX9Ut3pKjLJ7QDQsUnhoMsmpThSSpXI/KVRJ+wlU1Tj0gKW7ckfgx4ljNDJ9CFbkgA7uPFP97YYkDtaf7N4px51NkBDpA9wyhpOjOXGeYrQzK6391SbOG/FLxKropOq28qSBk2QuNiJ+tOeejoLK7eufRlV9u7FTiLfA45eo+V8X7df44W72BSsZvPwhd/WP3ZTDma9tMlZ2p0v6KRCYq8ZVTFxJo9aBpWbPQkOiO7PZcYD45a8qPPDwU8v3kaMkZ4DmcjSOwIhUMHh2Eyh2zhDrY3SQ0qoFX1z4HAQPMkG8XU6JDi1rYnQaADTcanZw0q8RtEXSgkgfsI2A3ySIVJ9HE8qSj1rLqUWhepaypDD87cOfcQydcBixeDO1s1L5l13J9MsducvaWJVSeMcVmK4g9gUqUxQt2QINat+wk1NxM7pchWTjjpKsztX+85S/HPTO+1z6d5M0YKvcoGaeiAWZHqKbH459A57G5GMyeGfJyObFUZ6zKqjxq4oLgF+20o9HyqIKhB4FcrQymguxoouqLrlca1vBdWP2RJUb2v8JIYLOc948xFULLxbtGhF0ltlZVm53f08J9dEVwJLnW9v+t9fOxasa/AKghO4=----ATTACHMENT:----NjAyMjI0ODcyNjI4NjA5NCA5NDMyNzQ1ODg5MzExMDc2IDk1MjU2NDQ3MzM3NDAwMjA=