Skip to content

Commit

Permalink
Stop translating menu item names for nothing on every request
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 21, 2024
1 parent caf898c commit 14129df
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions src/Menu/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ public function createUserMenu(): ItemInterface
$menu->setChildrenAttribute('class', 'list-unstyled');

$this->addProfileMenu($menu);
$menu->addChild('hr', ['label' => '<hr>', 'labelAttributes' => ['class' => 'normal'], 'extras' => ['safe_label' => true]]);
$menu->addChild($this->translator->trans('menu.logout'), ['label' => '<span class="icon-off"></span>' . $this->translator->trans('menu.logout'), 'uri' => $this->logoutUrlGenerator->getLogoutPath(), 'extras' => ['safe_label' => true]]);
$menu->addChild('hr', [
'label' => '<hr>',
'labelAttributes' => ['class' => 'normal'],
'extras' => ['safe_label' => true, 'translation_domain' => false],
]);
$menu->addChild($this->translator->trans('menu.logout'), [
'label' => '<span class="icon-off"></span>' . $this->translator->trans('menu.logout'),
'uri' => $this->logoutUrlGenerator->getLogoutPath(),
'extras' => ['safe_label' => true, 'translation_domain' => false],
]);

return $menu;
}
Expand All @@ -54,11 +62,38 @@ public function createProfileMenu(): ItemInterface

private function addProfileMenu(ItemInterface $menu): void
{
$menu->addChild($this->translator->trans('menu.profile'), ['label' => '<span class="icon-vcard"></span>' . $this->translator->trans('menu.profile'), 'route' => 'my_profile', 'extras' => ['safe_label' => true]]);
$menu->addChild($this->translator->trans('menu.settings'), ['label' => '<span class="icon-tools"></span>' . $this->translator->trans('menu.settings'), 'route' => 'edit_profile', 'extras' => ['safe_label' => true]]);
$menu->addChild($this->translator->trans('menu.change_password'), ['label' => '<span class="icon-key"></span>' . $this->translator->trans('menu.change_password'), 'route' => 'change_password', 'extras' => ['safe_label' => true]]);
$menu->addChild($this->translator->trans('menu.configure_2fa'), ['label' => '<span class="icon-mobile"></span>' . $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' => '<span class="icon-box"></span>' . $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' => '<span class="icon-leaf"></span>' . $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' => '<span class="icon-vcard"></span>' . $this->translator->trans('menu.profile'),
'route' => 'my_profile',
'extras' => ['safe_label' => true, 'translation_domain' => false],
]);
$menu->addChild($this->translator->trans('menu.settings'), [
'label' => '<span class="icon-tools"></span>' . $this->translator->trans('menu.settings'),
'route' => 'edit_profile',
'extras' => ['safe_label' => true, 'translation_domain' => false],
]);
$menu->addChild($this->translator->trans('menu.change_password'), [
'label' => '<span class="icon-key"></span>' . $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' => '<span class="icon-mobile"></span>' . $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' => '<span class="icon-box"></span>' . $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' => '<span class="icon-leaf"></span>' . $this->translator->trans('menu.my_favorites'),
'route' => 'user_favorites',
'routeParameters' => ['name' => $this->username],
'extras' => ['safe_label' => true, 'translation_domain' => false],
]);
}
}

0 comments on commit 14129df

Please sign in to comment.