View Single Post
  #1 (permalink)  
Old 07-30-2007, 09:36 AM
ashish.sharma ashish.sharma is offline
Junior Member
 
Join Date: Jul 2007
Posts: 4
Unhappy What is the best approach for Zend_Translate?

Hi ALL,

I am new to zend and still in learning process. Currently I am working on Zend_Translate and would like to know the best approach to use the Zend_Translate.

I am able to create .mo files and getting the translated content. Now, I would like to know the best way of getting the translated text so that i can use the same easily into my views.

Earlier I have created the Translate object into the controller and then assign the translated value to a view variable to get it displayed.

Code :

$this->view->lang = $this_request->getParam('lang');

Zend_Loader::loadClass('Zend_Translate');
$translationFilePath = '../languages/' . $this->view->lang . '/LC_MESSAGES/source-' . $this->view->lang . '.mo';
$translate = new Zend_Translate('gettext', $translationFilePath);

$this->view->welcomeText = $translate->_('Welcome User');

But if I use the above code then I have to use the same code in each controller for almost each view and this is what I don't want.

Then I have created a View helper having a function "translate", taking messageString as an argument. This function loads the .mo files and return the translated string. But I don't think that it is a good approach as it loads the .mo file each time i call translate() function

Can anyone suggest the best approach of doing this task?

1. What if i load the .mo file in the bootstrap file and store it's object into Registry to use it latter? Is it ok? Considering that I am having some large data for translation.

Please help!

Ashish Sharma
Reply With Quote