Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2007, 09:36 AM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-30-2007, 12:51 PM
SpotSec's Avatar
Senior Member
 
Join Date: Feb 2007
Location: United States
Posts: 115
Default

simply create a view helper... btw, view helpers can have more than one function if your wondering
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-04-2008, 11:47 PM
Junior Member
 
Join Date: Dec 2007
Posts: 3
Default

I was going to go with the bootstrap/registry approach as well...

what are the pros/cons to this approach vs the view helper spotsec mentioned? i'm mostly concerned with performance...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:26 PM.