2008年9月18日星期四

[fw-mvc] Re: Correct way to create a _()-ViewHelper for translations

I'm forwarding this in behalf of "The WRS", as it finished off-list:

I opted for a global function which is defined as part of my bootstrap file

$tr = new Zend_Translate(...);
Zend_Registry::set('tr', $tr);
function _($messageId = null){
return Zend_Registry::get('tr')->translate($messageId);
}
Other than some basic testing I havn't fully implements language support
across my application, so perhaps I've overlooked a benifit from using a
view helper for this.

You could also inform your .pot generating scripts to look for a token
other than _("")

Thomas Gelf schrieb:
> As most scripts creating .pot files by parsing PHP source code expect
> a _() function, I really would like to keep them ;-) So as the easiest
> solution I figured out the following one:
>
> > // Filename: My/View/Helper/.php
> >
> > class My_View_Helper__ extends Zend_View_Helper_Translate
> > {
> > public function _($messageid = null)
> > {
> > return $this->translate($messageid);
> > }
> > }
>
> As of the unusual file- and class-name it looks like an awful hack,
> so my question is: is this the right way to do what I'm wanting to
> achieve? And if so: would it make sense for ZF to provide a
> _()-ViewHelper per default?
>
> Kind regards,
> Thomas Gelf
>
>
>

没有评论: