-
Notifications
You must be signed in to change notification settings - Fork 33
usage documentation for zf3 not meaningful/correct #20
Comments
The problem is missing aliases. In zend-servicemanager v2, we performed normalization that would transform So, the problem here is that we only define |
@weierophinney hope the PR is correct 🐙 btw. I saw this in the |
No, it should be changed to |
obviously there is already a pull request by @samsonasik with zendframework/zend-i18n#56 |
@rogatec I suppose that |
@bartoszzajac your url behind the link is broken ;) I have a custom public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
{
$config = $container->get('config');
if (!isset($config['translator']['locale'])) {
throw new InvalidArgumentException("translator/locale array part missing in global config file");
}
$translator = new Translator();
$translator->addTranslationFilePattern(
PhpArray::class,
Resources::getBasePath(),
Resources::getPatternForValidator()
);
$translator->setLocale($config['translator']['locale']);
return new \Zend\Mvc\I18n\Translator($translator);
} In the 'service_manager' => [
'factories' => [
// other module factories
],
'delegators' => [
\Zend\Mvc\I18n\Translator::class => [
TranslatorDelegator::class,
],
],
], Lastly to get things working I implemented the public function onBootstrap(MvcEvent $event)
{
/** @var Translator $translator */
$translator = $event->getApplication()->getServiceManager()->get(Translator::class);
AbstractValidator::setDefaultTranslator($translator);
} I hope this can answer your question. If not please provide a little bit of your code implementation. |
Broken link is official documentation: https://github.com/zendframework/zend-i18n-resources/blob/master/doc/book/usage.md#automating-resource-injection (I just copied this file). You did this in some different way. I need to analyse that. |
I have to admit, that I also tried it for several hours and the working solution from the previous comment is my result :-/ I don't know if this is the correct way. |
@rogatec can you tell what is your file structure for TranslatorDelegator? |
therefore my namespace is |
Do you have 'factories' key for TranslatorDelegator in service_manager config? |
No, only 'service_manager' => [
'delegators' => [
\Zend\Mvc\I18n\Translator::class => [
TranslatorDelegator::class,
],
],
], |
Ok it is working now. I missed onBootstrap part that you have provided. I haven't change TranslatorDelegator from documentation so it is working. |
Thanks a lot @rogatec!!! You saved my day. As said at #106 on zend-validator 'phpArray' is now 'phparray'. |
That's the fastest way without configuring delegators:
|
When using the
addTranslationFilePattern
the first parameter is given as a string in the documentationphpArray
.In Zend Framework 3 the
loadMessagesFromPatterns
in theTranslator
class uses this string to get the plugin from the PluginManager (in line 655).Unfortunately this throws an exception because the PluginManager can't handle
phpArray
as a string(?).If I explicitly use the class reference it is working.
working solution:
Additionally I recognized that the config array should also look like this to work properly, only using a string like
MvcTranslator
didn't work:Maybe to give other users a better understanding this can be adjusted?
I think the problem occurs, when using the complete zend framwork which brings other classes with the same name like those to
phpArray
The text was updated successfully, but these errors were encountered: