I18n for your Menu Labels
The KnpMenuBundle translates all menu items by default. Assume you've built a menu like this:
1 2 3 4
$menu = $factory->createItem('root');
$menu->addChild('Home', ['route' => 'homepage']);
$menu->addChild('Login', ['route' => 'login']);
The items "Home" and "Login" can now be translated in the message domain:
1 2 3
# translations/messages.fr.yaml
Home: Accueil
Login: Connexion
Configure the Translation Domain
You can configure the translation domain that's used in the extras of the menu item:
1 2 3
// ...
$menu->addChild('Home', ['route' => 'homepage'])
->setExtra('translation_domain', 'AcmeAdminBundle');
Disabling Translation
You can disable translation of the menu item by setting translation_domain
to false
.
This work, including the code samples, is licensed under a
Creative Commons BY-SA 3.0 license.