diff --git a/packages/mailer/Twig/TranslationExtension.php b/packages/mailer/Twig/TranslationExtension.php index 0d208b18a..092e5e34e 100644 --- a/packages/mailer/Twig/TranslationExtension.php +++ b/packages/mailer/Twig/TranslationExtension.php @@ -2,6 +2,8 @@ namespace Draw\Component\Mailer\Twig; +use Symfony\Component\Translation\TranslatableMessage; +use Symfony\Contracts\Translation\TranslatableInterface; use Symfony\Contracts\Translation\TranslatorInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; @@ -19,10 +21,7 @@ public function getFilters(): array ]; } - /** - * @param string|string[] $messages - */ - public function trans(string|array $messages, array $arguments = [], ?string $domain = null, ?string $locale = null, ?int $count = null): ?string + public function trans(null|string|\Stringable|array|TranslatableInterface $messages, string|array $arguments = [], ?string $domain = null, ?string $locale = null, ?int $count = null): ?string { if (!\is_array($messages)) { $messages = [$messages]; @@ -34,6 +33,20 @@ public function trans(string|array $messages, array $arguments = [], ?string $do $result = reset($messages); foreach ($messages as $message) { + if ($message instanceof TranslatableInterface) { + if ($message instanceof TranslatableMessage && '' === $message->getMessage()) { + return ''; + } + + $result = $message->trans($this->translator, $locale ?? (\is_string($arguments) ? $arguments : null)); + + if ($result != $message) { + return $result; + } + + continue; + } + $result = $this->translator->trans($message, $arguments, $domain, $locale); if ($result != $message) { return $result; diff --git a/packages/sonata-extra-bundle/Configuration/SonataAdminNodeConfiguration.php b/packages/sonata-extra-bundle/Configuration/SonataAdminNodeConfiguration.php index 1ad288fb5..f3ce93096 100644 --- a/packages/sonata-extra-bundle/Configuration/SonataAdminNodeConfiguration.php +++ b/packages/sonata-extra-bundle/Configuration/SonataAdminNodeConfiguration.php @@ -23,6 +23,7 @@ public function __construct( ->scalarNode('controller_class')->defaultValue('sonata.admin.controller.crud')->end() ->scalarNode('icon')->defaultNull()->end() ->scalarNode('label')->defaultNull()->end() + ->scalarNode('translation_domain')->defaultValue('SonataAdminBundle')->end() ->scalarNode('show_in_dashboard')->defaultTrue()->end() ->enumNode('pager_type')->values(['default', 'simple'])->defaultValue('default')->end() ->end(); @@ -64,7 +65,7 @@ public static function configureFromConfiguration(Definition $definition, array array_filter( array_intersect_key( $config, - array_flip(['group', 'icon', 'label', 'pager_type', 'show_in_dashboard']) + array_flip(['group', 'icon', 'label', 'pager_type', 'show_in_dashboard', 'translation_domain']) ) + ['manager_type' => 'orm', 'model_class' => $config['entity_class'], 'controller' => $config['controller_class']], fn ($value) => null !== $value ) diff --git a/packages/sonata-extra-bundle/Resources/views/Block/block_monitoring.html.twig b/packages/sonata-extra-bundle/Resources/views/Block/block_monitoring.html.twig index 8ad102abf..d76bcd162 100644 --- a/packages/sonata-extra-bundle/Resources/views/Block/block_monitoring.html.twig +++ b/packages/sonata-extra-bundle/Resources/views/Block/block_monitoring.html.twig @@ -18,7 +18,7 @@ {% if link %} - {{ link_label|trans({}, 'SonataAdminBundle') }} + {{ link_label|trans({}, translation_domain) }} {% endif %} diff --git a/packages/sonata-extra-bundle/Resources/views/CRUD/show_prevent_delete.html.twig b/packages/sonata-extra-bundle/Resources/views/CRUD/show_prevent_delete.html.twig index 057181d81..08bf575c2 100644 --- a/packages/sonata-extra-bundle/Resources/views/CRUD/show_prevent_delete.html.twig +++ b/packages/sonata-extra-bundle/Resources/views/CRUD/show_prevent_delete.html.twig @@ -39,7 +39,7 @@ {% if filter_url %} - List + {{ 'link_list'|trans({}, 'SonataAdminBundle') }} {% endif %} diff --git a/packages/sonata-integration-bundle/Tests/DependencyInjection/ConfigurationTest.php b/packages/sonata-integration-bundle/Tests/DependencyInjection/ConfigurationTest.php index 0bc981f7f..e0c6f9779 100644 --- a/packages/sonata-integration-bundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/packages/sonata-integration-bundle/Tests/DependencyInjection/ConfigurationTest.php @@ -35,6 +35,7 @@ public function getDefaultConfiguration(): array 'label' => 'config', 'pager_type' => 'default', 'show_in_dashboard' => true, + 'translation_domain' => 'SonataAdminBundle', ], ], 'console' => [ @@ -47,6 +48,7 @@ public function getDefaultConfiguration(): array 'label' => 'Execution', 'pager_type' => 'simple', 'show_in_dashboard' => true, + 'translation_domain' => 'SonataAdminBundle', ], 'commands' => [], ], @@ -60,6 +62,7 @@ public function getDefaultConfiguration(): array 'label' => 'Migration', 'pager_type' => 'default', 'show_in_dashboard' => true, + 'translation_domain' => 'SonataAdminBundle', ], ], 'messenger' => [ @@ -76,6 +79,7 @@ public function getDefaultConfiguration(): array 'label' => 'Message', 'pager_type' => 'simple', 'show_in_dashboard' => true, + 'translation_domain' => 'SonataAdminBundle', 'enabled' => true, ], ], @@ -110,6 +114,7 @@ public function getDefaultConfiguration(): array 'label' => 'User lock', 'pager_type' => 'simple', 'show_in_dashboard' => true, + 'translation_domain' => 'SonataAdminBundle', ], ], ],