From 14129dfd8074aac5398a4040d17cfaa595847f27 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 21 Mar 2024 15:09:57 +0100 Subject: [PATCH] Stop translating menu item names for nothing on every request --- src/Menu/MenuBuilder.php | 51 +++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/Menu/MenuBuilder.php b/src/Menu/MenuBuilder.php index bf5fbef49..0a2ff1a37 100644 --- a/src/Menu/MenuBuilder.php +++ b/src/Menu/MenuBuilder.php @@ -36,8 +36,16 @@ public function createUserMenu(): ItemInterface $menu->setChildrenAttribute('class', 'list-unstyled'); $this->addProfileMenu($menu); - $menu->addChild('hr', ['label' => '
', 'labelAttributes' => ['class' => 'normal'], 'extras' => ['safe_label' => true]]); - $menu->addChild($this->translator->trans('menu.logout'), ['label' => '' . $this->translator->trans('menu.logout'), 'uri' => $this->logoutUrlGenerator->getLogoutPath(), 'extras' => ['safe_label' => true]]); + $menu->addChild('hr', [ + 'label' => '
', + 'labelAttributes' => ['class' => 'normal'], + 'extras' => ['safe_label' => true, 'translation_domain' => false], + ]); + $menu->addChild($this->translator->trans('menu.logout'), [ + 'label' => '' . $this->translator->trans('menu.logout'), + 'uri' => $this->logoutUrlGenerator->getLogoutPath(), + 'extras' => ['safe_label' => true, 'translation_domain' => false], + ]); return $menu; } @@ -54,11 +62,38 @@ public function createProfileMenu(): ItemInterface private function addProfileMenu(ItemInterface $menu): void { - $menu->addChild($this->translator->trans('menu.profile'), ['label' => '' . $this->translator->trans('menu.profile'), 'route' => 'my_profile', 'extras' => ['safe_label' => true]]); - $menu->addChild($this->translator->trans('menu.settings'), ['label' => '' . $this->translator->trans('menu.settings'), 'route' => 'edit_profile', 'extras' => ['safe_label' => true]]); - $menu->addChild($this->translator->trans('menu.change_password'), ['label' => '' . $this->translator->trans('menu.change_password'), 'route' => 'change_password', 'extras' => ['safe_label' => true]]); - $menu->addChild($this->translator->trans('menu.configure_2fa'), ['label' => '' . $this->translator->trans('menu.configure_2fa'), 'route' => 'user_2fa_configure', 'routeParameters' => ['name' => $this->username], 'extras' => ['safe_label' => true]]); - $menu->addChild($this->translator->trans('menu.my_packages'), ['label' => '' . $this->translator->trans('menu.my_packages'), 'route' => 'user_packages', 'routeParameters' => ['name' => $this->username], 'extras' => ['safe_label' => true]]); - $menu->addChild($this->translator->trans('menu.my_favorites'), ['label' => '' . $this->translator->trans('menu.my_favorites'), 'route' => 'user_favorites', 'routeParameters' => ['name' => $this->username], 'extras' => ['safe_label' => true]]); + $menu->addChild($this->translator->trans('menu.profile'), [ + 'label' => '' . $this->translator->trans('menu.profile'), + 'route' => 'my_profile', + 'extras' => ['safe_label' => true, 'translation_domain' => false], + ]); + $menu->addChild($this->translator->trans('menu.settings'), [ + 'label' => '' . $this->translator->trans('menu.settings'), + 'route' => 'edit_profile', + 'extras' => ['safe_label' => true, 'translation_domain' => false], + ]); + $menu->addChild($this->translator->trans('menu.change_password'), [ + 'label' => '' . $this->translator->trans('menu.change_password'), + 'route' => 'change_password', + 'extras' => ['safe_label' => true, 'translation_domain' => false], + ]); + $menu->addChild($this->translator->trans('menu.configure_2fa'), [ + 'label' => '' . $this->translator->trans('menu.configure_2fa'), + 'route' => 'user_2fa_configure', + 'routeParameters' => ['name' => $this->username], + 'extras' => ['safe_label' => true, 'translation_domain' => false], + ]); + $menu->addChild($this->translator->trans('menu.my_packages'), [ + 'label' => '' . $this->translator->trans('menu.my_packages'), + 'route' => 'user_packages', + 'routeParameters' => ['name' => $this->username], + 'extras' => ['safe_label' => true, 'translation_domain' => false], + ]); + $menu->addChild($this->translator->trans('menu.my_favorites'), [ + 'label' => '' . $this->translator->trans('menu.my_favorites'), + 'route' => 'user_favorites', + 'routeParameters' => ['name' => $this->username], + 'extras' => ['safe_label' => true, 'translation_domain' => false], + ]); } }