0

I define a translation pattern in one of my plugin and it work fine in the views but i have other plugin witch create an html for menus and i need it to fill with curent translation of worlds , but when i use :

   public function preDispatch(Zend_Controller_Request_Abstract $request){
    .......
    $translate = Zend_Registry::get('Zend_Translate');
    $translate->_($Nrow['name']);
    .......

It give me :

Message: No entry is registered for key 'Zend_Translate'

But if i use print_r($translate); it shows content of my translation file .

And When i use print_r(get_class_methods($translate)); it returns :

Array ( [0] => __construct [1] => setAdapter [2] => getAdapter [3] => getCache [4] => setCache [5] => hasCache [6] => removeCache [7] => clearCache [8] => __call )

I use these code in my translation plugin to set registery:

Zend_Registry::set('Zend_Translate',$translate);

What should i do ?

2 Answers2

0

Place that in your bootstrap:

$translate = new Zend_Translate('YOURADAPTER', YOURLANG); 
Zend_Registry::set('Zend_Translate', $translate); 

Now you should be able to access this via:

$translations = Zend_Registry::get('Zend_Translate'); 
// or operate on it directly: 
$translation = Zend_Registry::get('Zend_Translate')->translate($string); 
axel.michel
  • 5,764
  • 1
  • 15
  • 25
  • yes , but i need to get user request "Zend_Controller_Request_Abstract $request" to fill my parameter "$translate = new Zend_Translate('array',APPLICATION_PATH.'/configs/lang/'.$lang.'.php',$lang);" but it shoudbe [avoided](http://stackoverflow.com/questions/2622879/zend-framework-getting-request-object-in-bootstrap) . –  Jan 08 '13 at 07:28
  • You could do this by setting the default in the bootsrap, and adding the current language with addTranslation and setLocale? – axel.michel Jan 08 '13 at 07:35
  • If i add default language to bootstrap it means all the times Zend Translate the words in that language . I think i am looking for a solution witch set Zend_Registry in Plugins .is it possible ? –  Jan 08 '13 at 07:50
0

As i understand preDispatch run before calling Zend_Registry , If you want to have Zend_Registry keys , you should put code in postDispatch function in Zend_Controller_Plugin_Abstract or in your plugin class.

Code change to these and problem solved :

   public function preDispatch(Zend_Controller_Request_Abstract $request){
    .......
    $translate = Zend_Registry::get('Zend_Translate');
    $translate->_($Nrow['name']);
    .......

for more info look at :

http://devzone.zend.com/1224/front-controller-plugins-in-zend-framework/