Joined December 2013
·
Posted to
How to translate zend framework 2 config arrays
over 1 year
ago
Hi !
When I tried your method, I had issue because no translator was specified... poedit regognized it... navigation was translated... but not beadcrumbs... (don't ask me why).
But I found here a great part of the solution !
Instead of instanciating an empty translator, I called the factory() method wich returns a fully operationnal translator :) the only problem was to inject options
=> Before that, I write the translator's options in a separate autoload file (only one language folder for my entire application) :
config/autoload/translator.global.php
and now it works :
<?php
$config = require 'translator.global.php';
$options = (array)$config['translator'];
$translator = \Zend\I18n\Translator\Translator::factory($options);
//$translator = new \Zend\I18n\Translator\Translator;
return array(
'navigation' => array(
'default' => array(
array(
'label' => $translator->translate('Home'),
'route' => 'home',
),
[...]
),
),
);
notice that I also put all the navigation in config/autoload/navigation.global.php file
@aimfeld: Thanks for your answers :)
Infact, I do translate for multiple language, but not with this code ;)
=> this was my configuration for the default language of my application :) ( but you're almost right :I didn't implement it yet when I posted last night ;) )
but I did inbeetween :)
=> I only implemented multiple languages for registred users.
so I integrated in my ACL :
As I check the user level, I also get his favorite language (set on registration)
in my ACL : module/MyAclLib/module.php :
of course, it is not enough : the patch for navigation breadcrumbs still translate in french (default language of my app).
to fix it, I make the same chek in config/autoload/navigation.global.php like this :
evenything works perfectly for me like this now :)