I'm trying to translate the breadcrumbs sitting in the module/Application/config/module.config.php
configuration file like:
'navigation' => array(
'default' => array(
array(
'label' => \Application\Util\Translator::translate('Home'),
'route' => 'home',
'resource' => 'route/home',
'pages' => array(
),
),
The breadcrumb Home
should display as Accueil
in french.
The translator works just fine for the rest of the application. But none of the breadcrumbs are translated. The language resource file has been verified and poedit-ed again and again.
In the very same configuration file, is the translator
configuration:
'service_manager' => array(
'factories' => array(
'account_navigation' => 'Application\Navigation\Service\AccountNavigationFactory',
'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
'Application\Collector\RouteCollector' => 'Application\Service\RouteCollectorServiceFactory',
),
),
'translator' => array(
'locale' => 'fr_FR', // langue par défaut
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
'translation_files' => array(
array(
'type' => 'phpArray',
'filename' => __DIR__ . '/../../../vendor/zendframework/zendframework/resources/languages/fr/Zend_Validate.php',
'locale' => 'fr_FR'
),
array(
'type' => 'gettext',
'filename' => __DIR__ . '/../../../vendor/zf-commons/zfc-user/src/ZfcUser/language/fr_FR.mo',
'locale' => 'fr_FR'
),
array(
'type' => 'phpArray',
'filename' => __DIR__ . '/../language/fr_FR.php',
'locale' => 'fr_FR'
)
)
),
My application bootstrap looks like:
class Module
{
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$sm = $e->getParam('application')->getServiceManager();
// Add ACL information to the Navigation view helper
$authorize = $sm->get('BjyAuthorize\Service\Authorize');
$acl = $authorize->getAcl();
$role = $authorize->getIdentity();
\Zend\View\Helper\Navigation::setDefaultAcl($acl);
\Zend\View\Helper\Navigation::setDefaultRole($role);
$id = $sm->get('zfcuser_auth_service')->getIdentity();
if (! is_null($id)) {
$em = $sm->get('Doctrine\ORM\EntityManager');
$usr = $em->find('Application\Entity\User', $id->getId());
$blameableListener = new \Gedmo\Blameable\BlameableListener();
$blameableListener->setUserValue($usr);
$em->getEventManager()->addEventSubscriber($blameableListener);
} else {
// redirection
if (isset($_SERVER['SERVER_NAME']) && preg_match('/monxxxxx/', $_SERVER['SERVER_NAME'])) {
$strategy = new RedirectionStrategy();
$strategy->setRedirectRoute('driver/login');
$eventManager->attach($strategy);
}
}
if ($sm->has('MvcTranslator')) {
\Zend\Validator\AbstractValidator::setDefaultTranslator($sm->get('MvcTranslator'));
}
Locale::setDefault('fr_FR');
// custom layout
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController', 'dispatch', function($e) {
$route = $e->getRouteMatch();
$controller = $e->getTarget();
// change layout for login
if($route->getParam('controller') == 'zfcuser' && $route->getParam('action') == 'login'){
$controller->layout('layout/login');
}
}, 100);
// Log the exceptions
$application = $e->getApplication();
$sm = $application->getServiceManager();
$sharedManager = $application->getEventManager()->getSharedManager();
$sharedManager->attach('Zend\Mvc\Application', 'dispatch.error',
function($e) use ($sm) {
if ($e->getParam('exception') && strpos($e->getParam('exception'), 'are not authorized') === false) {
$sm->get('Zend\Log\Logger')->crit($e->getParam('exception'));
$toEmail = "xxxxx@xxxxx.com";
$toName = "Service IT";
$subject = "Exception error";
$body = $e->getParam('exception');
\Application\Util\Common::sendMail($toEmail, $toName, $subject, $body);
}
}
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
)
)
);
}
public function init($moduleManager)
{
$moduleManager->loadModule('ZfcUser');
}
}
I'm on ZF2 2.2.5
.