PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Creating Array source files

Array source files are plain arrays. But you have to define them manually since there is no tool to aid this. But because they are so simple, it's the fastest way to look up messages if your code works as expected. It's generally the best adapter to get started with translation business.

<?php
$english 
= array(
    
'message1' => 'message1',
    
'message2' => 'message2',
    
'message3' => 'message3');

$german = array(
    
'message1' => 'Nachricht1',
    
'message2' => 'Nachricht2',
    
'message3' => 'Nachricht3');

$translate = new Zend_Translate(
    array(
        
'adapter' => 'array',
        
'content' => $english,
        
'locale'  => 'en'
    
)
);
$translate->addTranslation(array('content' => $german'locale' => 'de'));

Since release 1.5 it is also supported to have arrays included within an external file. You just have to provide the filename and Zend_Translate will automatically include it and look for the array. See the following example for details:

<?php
// myarray.php
return array(
    
'message1' => 'Nachricht1',
    
'message2' => 'Nachricht2',
    
'message3' => 'Nachricht3');

// controller
$translate = new Zend_Translate(
    array(
        
'adapter' => 'array',
        
'content' => '/path/to/myarray.php',
        
'locale'  => 'de'
    
)
);

Note

Files which do not return an array will fail to be included. Also any output within this file will be ignored and suppressed.

Zend Framework