0
votes

I stuck with the $defaultLocale of the TranslatableListener.

https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/translatable.md#default-locale

I found only setup possibilities for Symphony, but not for Zend Framework 2.

There is an extension bundle for doctrine for easy setup of DoctrineExtensions named "StofDoctrineExtensionsBundle", but I didn't found something like that for ZF2.

The following link shows a best practices for setting up translatable and other DoctrineExtensions, but where should I put it and isn't there an easier approach?

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/annotations.md#best-practices-for-setting-up-with-annotations

I only want to know how I can configure the $defaultLocale of the TranslatableListener in a ZF2 environment.

UPDATE:

I tried in my bootstrap the following:

$translatableListener = new TranslatableListener();
$translatableListener->setDefaultLocale('de-DE');
$doctrineEventManager->addEventSubscriber($translatableListener);

But still getting:

.../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/TranslatableListener.php:464 Gedmo\Translatable\Mapping\Event\Adapter\ORM->loadTranslations

$object Rental\Entity\Rental
$translationClass "Rental\Entity\RentalTranslation" 
$locale "en_US" 
$objectClass "Rental\Entity\Rental"
2

2 Answers

1
votes

So my mistake was, that I configured the TranslatableListener twice.

In my doctrine configuration (only for explanation there is a comment before, delete the whole line):

'doctrine' => [       
    'eventmanager'             => [
        'orm_default' => [
            'subscribers' => [
                'Gedmo\Timestampable\TimestampableListener',
                'Gedmo\Sluggable\SluggableListener',
                // 'Gedmo\Translatable\TranslatableListener',
            ],
        ],
    ],

and in bootstrap:

// sets the default locale and the actual locale
 $translatableListener = new TranslatableListener();
 $translatableListener->setDefaultLocale('de-DE');
 $translatableListener->setTranslatableLocale(\Locale::getDefault());
 $doctrineEventManager->addEventSubscriber($translatableListener);

If you want to set the DefaultLocale and the TranslatableLocale in Zend Framework 2 for the Translatable Doctrine Extension, than do it in bootstrap and don't add it a second time in the doctrine configuration.

0
votes

If you want to keep:

'doctrine' => [       
'eventmanager'             => [
    'orm_default' => [
        'subscribers' => [
            'Gedmo\Timestampable\TimestampableListener',
            'Gedmo\Sluggable\SluggableListener',
            // the line below because in future you might need it
            'Gedmo\Translatable\TranslatableListener',
        ],
    ],
],

Try this: https://stackoverflow.com/a/42859119/3661592