From: Raphaƫl Gertz Date: Thu, 31 Oct 2024 05:47:55 +0000 (+0100) Subject: Set alias X-Git-Tag: 0.5.1~9 X-Git-Url: https://git.rapsys.eu/userbundle/commitdiff_plain/3469edb1180f264977e509d8ca4c4dfe15357cf8?ds=inline;hp=1aa803557744dc452cd804fe8d0ae55771b4ce39 Set alias Use bundle alias as translation domain Set relative canonical path as self_url --- diff --git a/Controller/AbstractController.php b/Controller/AbstractController.php index 043a959..77cf860 100644 --- a/Controller/AbstractController.php +++ b/Controller/AbstractController.php @@ -46,6 +46,11 @@ use Twig\Environment; * Provides common features needed in controllers. */ abstract class AbstractController extends BaseAbstractController implements ServiceSubscriberInterface { + /** + * Alias string + */ + protected string $alias; + /** * Config array */ @@ -93,7 +98,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv */ public function __construct(protected CacheInterface $cache, protected AuthorizationCheckerInterface $checker, protected ContainerInterface $container, protected ManagerRegistry $doctrine, protected FormFactoryInterface $factory, protected UserPasswordHasherInterface $hasher, protected LoggerInterface $logger, protected MailerInterface $mailer, protected EntityManagerInterface $manager, protected RouterInterface $router, protected Security $security, protected SluggerUtil $slugger, protected RequestStack $stack, protected TranslatorInterface $translator, protected Environment $twig, protected int $limit = 5) { //Retrieve config - $this->config = $container->getParameter(RapsysUserBundle::getAlias()); + $this->config = $container->getParameter($this->alias = RapsysUserBundle::getAlias()); //Get current request $this->request = $stack->getCurrentRequest(); @@ -198,7 +203,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv } //Translate tmp value - $tmp = $this->translator->trans($tmp); + $tmp = $this->translator->trans($tmp, [], $this->alias); //Iterate on keys foreach(array_reverse($keys) as $curkey) { @@ -223,7 +228,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv //Iterate on other locales foreach(array_diff($locales, [$locale]) as $other) { - $titles[$other] = $this->translator->trans($this->config['default']['languages'][$locale], [], null, $other); + $titles[$other] = $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $other); } //Retrieve route matching path @@ -239,13 +244,14 @@ abstract class AbstractController extends BaseAbstractController implements Serv if ($locale == $this->locale) { //Set locale locales context $this->config[$tag][$view]['context']['canonical'] = $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL); + $this->config[$tag][$view]['context']['self_url'] = $this->router->generate($name, ['_locale' => $locale]+$route); } else { //Set locale locales context $this->config[$tag][$view]['context']['alternates'][$locale] = [ 'absolute' => $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL), 'relative' => $this->router->generate($name, ['_locale' => $locale]+$route), 'title' => implode('/', $titles), - 'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], null, $locale) + 'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $locale) ]; } @@ -256,7 +262,7 @@ abstract class AbstractController extends BaseAbstractController implements Serv 'absolute' => $this->router->generate($name, ['_locale' => $locale]+$route, UrlGeneratorInterface::ABSOLUTE_URL), 'relative' => $this->router->generate($name, ['_locale' => $locale]+$route), 'title' => implode('/', $titles), - 'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], null, $locale) + 'translated' => $this->translator->trans($this->config['default']['languages'][$locale], [], $this->alias, $locale) ]; } }