4.4. Introduction

The Zend_Translate component provides the Zend Framework with message translation functionality. It can handle pre-translated strings stored in different source file formats.

The Zend Framework offers common way to prepare multi-lingual applications.

PHP code operates with strings identifiers, which are translated to actual used strings at run time.

Translated strings can be stored in different source file formats. PHP arrays and gettext (.mo) files are supported now.

Module usage example:

Example 4.1. Zend_Translate module usage example:

<?php
...
$lang = new Zend_Translate(Zend_Translate::AN_ARRAY,
                           array('Message 1' => 'Message 1',
                                 'Message 2' => 'Message 2',
                                 'Message 3' => 'Message 3'
                                ),
                           'en');

$lang->addTranslation('de',
                      array('Message 1' => 'Nachricht 1',
                            'Message 2' => 'Nachricht 2',
                            'Message 3' => 'Nachricht 3'
                           ),
                     );

$lang->addTranslation('ru',
                      array('Message 1' => 'Сообщение 1',
                            'Message 2' => 'Сообщение 2',
                            'Message 3' => 'Сообщение 3'
                           ),
                     );

...

$lang->setLanguage('de');

...

echo $lang->_('Message 2');

...
?>
            

It prints 'Nachricht 2'.