ZF-1965: Easier use of printf functionality. Maybe an enhancement of the _() method
Description
Edit: Woops. This looks like a duplicate of http://framework.zend.com/issues/browse/ZF-1116 .
The goal is to ease the typical use where one wishes to use the printf family of functions to substitute parameters into a translated string. I can not see why this should not be an enhancement of the _() method.
This suggested implementation is written as a method extending the current _() method:
public function _(/*$messageId, args... */){
$args = func_get_args();
if(is_array($args[0])){
$args = $args[0];
}
$messageId = array_shift($args);
return vsprintf(parent::_($messageId), $args);
}
An additional feature of this implementation is that it allows calling this method with the all parameters given in an array in the first parameter. This is to allow easy calling from other places, for instance a view helper, with the content from a func_get_args().
Comments
Posted by Darby Felton (darby) on 2007-09-19T14:24:29.000+0000
Assigning to [~thomas] to initiate issue review.
Posted by Thomas Weidner (thomas) on 2007-09-19T15:18:53.000+0000
We already discussed such implementation details in the past. It was declared that Zend_Translate should not do view-code.
As option I created a new proposal for adding a Translation_View_Helper... it is not finished for now as I added it some days ago. But this component will add such feature in future.
Posted by Thomas Weidner (thomas) on 2007-09-19T15:35:10.000+0000
The detailed resons for this decission can be found in these two issues:
http://framework.zend.com/issues/browse/ZF-1096 http://framework.zend.com/issues/browse/ZF-1116
Posted by Jacob Oettinger (oetting) on 2007-09-19T15:41:17.000+0000
Thank you for the clarification.
I guess my current helper methods is the way to do it then.
Posted by Martin Keckeis (thadafinser) on 2010-12-07T01:02:18.000+0000
I this really planned for the view?
It would be nice for classes to just set the complete translation message.
Example: Reading an excel file from an user and an error occure in cell "B2". The errors are collected in an array, if you wand to translate it outside (view), you have to collect all untranslated message plus all parameters!
Easier is to translate and parse the parameter just in the class. So currently you have to use the printf function in the parsing class.
+VOTE for it+
Posted by Thomas Weidner (thomas) on 2010-12-08T11:41:39.000+0000
This issue has been closed more than 3 years ago as won't fix. Why do you come to the idea that it is now planned to integrate view code within Zend_Translate?