ZF-1096: Add autoechoing function
Description
For simplication we could add a auto-print function...
public function print($messageId, $locale = null, array $parameters)
{
sprintf ($this->_adapter->translate($messageId, $locale), $parameters);
}
So a user would have a simplification of it's view:
// old
print $translate->translate('mystring', $locale);
sprintf( $translate->translate('mystring', $locale), $firstparam, $secondparam, $thirdparam);
// new
$translate->print('mystring', $locale);
$translate->print('mystring', $locale, $parameters);
Less code to write for the user and simplification as also much more readability. Ideas, Thoughts, to implement until which version ??
Comments
Posted by Alexander Veremyev (alexander) on 2007-03-22T06:06:00.000+0000
I don't think print() should be added to translate functionality.
Zend_Translate knows nothing about output method we use in our application. It may be HTML/WML/XML/plain text/... It also may be View part of MVC paradigm offered by in ZF.
I don't think we have to distinguish this one output method.
From the other side userland code simplification is important goal for the framework. Such simplification may be also done in userland and it may be a good example for Zend_Translate documentation ("How to use" example):
Posted by Thomas Weidner (thomas) on 2007-03-22T07:46:57.000+0000
Posted by Olivier Sirven (slaanesh) on 2007-03-22T08:23:51.000+0000
{quote} But this is no problem... Zend_Translate only prints the translated string. And within the translated content there is never a html / xml or whatever tag. {quote} Zend_Translate can not just print the translated string as it may need to be escaped first (again think about html rendering of the string "my stuff > your stuff"). You have to allow the user to decide how to ouput the string... so I think a solution would be something like this:
Posted by Thomas Weidner (thomas) on 2007-03-22T08:32:36.000+0000
That is logical oliver... but we should first decide IF such a functionality should be added before going into details.
And for now I only received contras and no pros...
Posted by Alexander Veremyev (alexander) on 2007-03-22T10:57:22.000+0000
May generate invalid XML if translate output contains '<', '&' and so on.
Posted by Thomas Weidner (thomas) on 2007-03-22T11:06:52.000+0000
This has already been pointed two comments before yours, Alexander... But these are details which can be solved later on.
The general question which I want to have solved is if we want to add such functionality or not.
Posted by Olivier Sirven (slaanesh) on 2007-03-22T11:20:20.000+0000
Anyway I think the rendering should not be done within Zend_Translate as it is not its job...I'd rather use the display method of my rendering engine....
Posted by Matthew Ratzloff (mratzloff) on 2007-03-22T12:52:49.000+0000
{quote} This has already been pointed two comments before yours, Alexander... But these are details which can be solved later on.
The general question which I want to have solved is if we want to add such functionality or not. {quote}
Issues like the one he pointed out are directly relevant as to whether functionality like this should be included or not. I really don't feel it's necessary or desirable to have {{Zend_Translate}} printing out strings.
Instead, the method signature of {{translate()}} should be changed to make it easier to use.
Instead of this:
It could be this:
Users really should never have to touch {{sprintf()}} to use {{Zend_Translate}}.
Posted by Thomas Weidner (thomas) on 2007-03-22T13:39:19.000+0000
The described functionallity was not accepted and as the idea proposed here got only negative feedback and not one positive I am closing this issue.
Posted by Darby Felton (darby) on 2007-03-22T13:53:30.000+0000
I would like to share my opinion in hopes of helping answer [~thomas]'s question:
I tend to agree that although such convenience code is attractive and useful, it appears to be more appropriate for userland. Including such an example in the documentation is a fine idea, provided that it encourages good PHP practices.
I feel that having the component write directly to STDOUT seems to unnecessarily couple the component to the view. Put another way, it would seem to be best practice to decouple the component from the responsibility of writing output and to allow the view logic to perform this, especially considering various output strategies, formats, and filtering requirements.
In summary, I would recommend against adding this to {{Zend_Translate}} proper.
Posted by Thomas Weidner (thomas) on 2007-03-23T03:01:07.000+0000
{quote}Instead, the method signature of translate() should be changed to make it easier to use. Users really should never have to touch sprintf() to use Zend_Translate.{quote}
I already had made this change but it was not accepted by the devteam, so I had to revert it to the old behaviour.