Search code examples
phpzend-frameworkzend-translate

How to get an ad hoc translation with Zend_Translate


I'm using Zend_Translated to translated all my strings

$translator->_('hello')

If my locale is in french this code will print "Bonjour".

When browsing the french version of the site i'd like to output some german text.

$translator->_('hello', array(locale=>'en'))

This will still output "Bonjour" but i'd like "Guten Tag"

How can I get a translation of a string in another language than the current locale?


Solution

  • If you would like to output some german text you should use

    $translator->setLocale('de');
    $translator->_('hello');
    

    or

    $translator->_('hello', 'de');
    

    ie. either set the locale before translating or specify the locale string as 2nd parameter.

    Refer to Handling languages for more information.