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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-10-2008, 11:52 PM
Junior Member
 
Join Date: Aug 2008
Posts: 6
Default Zend_Translate autocreating source

Is it possible to make Zend_Translate automatically create strings for translation according to it's request?

I mean for example I need to translate some form and it's error messages. Generally I don't know what exact message I will have and I desire to see translation source string of message in my translation file after first call of this.

... form code here ...
$firstname = new Zend_Form_Element_Text(.....)
$firstname->setLabel('Your firstname')
... form code ....

After I set translator for this form it should call translation functions when I render form. After first render I want to see "Your firstname" in my translation file (for example with gettext adapter) and empty translation for this. Is it possible?

PS. Why I ask this question? Primary because of usibility, secondary just imagine that I need to validate $firstname by LessThan Validator. It has a message template '%value%' is not less than '%max%', so actually as simple user I don't know what message used for this. Visually I see only "'[entered name]' is not less than '10'" for example and I don't know what to translate generally

Last edited by OmeZ : 08-10-2008 at 11:59 PM. Reason: PostScriptum
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-11-2008, 06:20 AM
Junior Member
 
Join Date: Aug 2007
Posts: 9
Send a message via ICQ to Mike
Default

Quote:
Is it possible?
Yes, it is. You just need to write a method, which takes the complete form object as an argument. In that method you can iterate over the form elements in order to get all the labels. Then use your Zend_Translate object and check whether the given label is already translated (isTranslated()) and if not append it to your .po file. You just need to make sure, that the method is called every time a form object is created.

If you want the keys of the errors, you have to call your method after submitting the form. $form->getErrors() will return an array with all occured errors.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-11-2008, 01:41 PM
Member
 
Join Date: Aug 2008
Posts: 52
Default

Beware that such a methodology is problematic in a production environment.

It will probably kill your performance.
__________________
Greetings
Thomas Weidner
I18N Team Leader, Zend Framework
http://www.thomasweidner.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-11-2008, 07:35 PM
Member
 
Join Date: Mar 2007
Posts: 41
Default

There was a thread on Czech board.

Have a look at shell script used for extraction from code. (you can use cygwin on windows).

I think, that poEdit has some function with the same purpose, but it is not very stable
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-11-2008, 07:49 PM
Junior Member
 
Join Date: Aug 2007
Posts: 9
Send a message via ICQ to Mike
Default

That shell script won't work in this case because there are no keywords which xgettext could find if you work with Zend_Form.

Quote:
I think, that poEdit has some function with the same purpose, but it is not very stable
Weird, I never had any stability issues with poEdit and I'm using it regularly.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-12-2008, 05:45 AM
Member
 
Join Date: Mar 2007
Posts: 41
Default

Quote:
Originally Posted by Mike View Post
Weird, I never had any stability issues with poEdit and I'm using it regularly.
You're a lucky man
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-14-2008, 07:02 AM
Junior Member
 
Join Date: Aug 2008
Posts: 6
Default

look, actually I thought about to use translation interface itself to do all dirty work. Maybe it's better to use some cover under method _() in translator object which first will check context for exsiting translation, if not - add a key into .po, gettext etc. I suppose it should be very useful in all situation not only when I translate form or something else. Also it could be used in production because adding key action will be called only once. What you think?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-14-2008, 07:20 AM
Member
 
Join Date: Aug 2008
Posts: 52
Default

There is no need to add something additionally to check if a translation is available.

When you look into Zend_Translate you will see that there is a isTranslated() method. Why not simply use this ?
__________________
Greetings
Thomas Weidner
I18N Team Leader, Zend Framework
http://www.thomasweidner.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-14-2008, 12:14 PM
Junior Member
 
Join Date: Aug 2008
Posts: 6
Default

of course, I know this, I just purpose the methodic. And of course we need to override all adapters and abstract translate class
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 03:23 PM.