ZF2: use translate view helper with modules

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ZF2: use translate view helper with modules

Ralf Eggert
Hi,

when installing the Skeleton application a translator object is
configured. This reads the translation files and works perfectly with
the translate() view helper. But now I have additional modules with
additional translation files in the module directory.

How can I add these additional texts to my translator object? Can it be
done through configuration within my module.config.php? Or should I
amend the Module.php file to set this up?

Best regards,

Ralf

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: ZF2: use translate view helper with modules

Ralf Eggert
Hi,

I just changed my User Module.php for an additional module to add more
translations to the translator object. Here is my code:

------------------------------------------------------------------------
namespace User;

class Module implements BootstrapListenerInterface
{
    public function onBootstrap(EventInterface $e)
    {
        $translator = $e->getApplication()->getServiceManager()
                        ->get('translator');

        $translator->addTranslationPattern(
            'phpArray', __DIR__ . '/language', '%s.php'
        );
    }
}
------------------------------------------------------------------------

When I use the translate view helper now all translations from my
Application module are gone and only the translations from my User
module are available.

I wonder, if this is a bug or a feature.

Regards,

Ralf

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: ZF2: use translate view helper with modules

Ralf Eggert
Hi again,

forget about it. Just found the textdomain parameter which can also be
passed to the translate view helper.

------------------------------------------------------------------------
namespace User;

class Module implements BootstrapListenerInterface
{
    public function onBootstrap(EventInterface $e)
    {
        $translator = $e->getApplication()->getServiceManager()
                        ->get('translator');

        $translator->addTranslationPattern(
            'phpArray', __DIR__ . '/language', '%s.php', 'user'
        );
    }
}
------------------------------------------------------------------------

Regards,

Ralf

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]