Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, not that I know of. There are several implicit issues related to that anyway. First, you should <em>always</em> give functions (and variables for that matter) <a href="http://www.webgeekly.com/tutorials/php/20-tips-you-need-to-learn-to-become-a-better-php-programmer/" rel="nofollow">meaningful names</a>. That said, <code>__()</code> is not a meaningful name at all. Quite the opposite, in fact, it has <em>no</em> meaning. Second of all, it is considered best practice to prefix <strong>only</strong> <code>private</code> and <code>protected</code> functions (and, again, variables for that matter) with an underscore.</p> <p>Finally, with the way zend view helpers work, you would pretty much have to sorta "trick" the system into locating your view helper if it was named __(). You would have to name it something like <code>Zend_View_Helper___</code> and that wouldn't work. Not to mention, that would entail having to name your file <code>__.php</code>.</p> <p>I suppose you could name your helper <code>Zend_View_Helper_T</code>, in which case you could translate stuff using <code>$this-&gt;t($string);</code> (I tested this and it works), but again you should always use <a href="http://en.wikipedia.org/wiki/Naming_convention_%28programming%29" rel="nofollow">meaningful names</a>.</p> <hr> <p><strong>Edit</strong></p> <p>Having not realized that you wanted to call this from within the <em>controller</em> until now, I decided to revise my answer and give a little feedback about the comment I received from the down voter..</p> <p>It's hard to recommend that you create a wrapper class for <code>Zend_Controller_Action</code> in which to create a function <code>_()</code> for the following reason:</p> <ul> <li>Because regardless it being an "accepted standard" or not, I reiterate that that <em>all</em> methods and variables should have a meaningful name. I must assert this because I am a firm believer in following <em>explicit</em> coding standards (as opposed to those "hearsay" or "recently-adopted" practices that don't directly correspond to a known - and thereby trusted - paradigm). That said, should PEAR, or even Zend, decide to adopt such a radical change some day, I will resign my disposition. NOTE: It could be argued that credible companies like Drupal and their self-proclaimed best practices could be considered explicit coding standards but I disagree. Why? Because PEAR is...well...it's PEAR. And Zend is "The PHP Company." It's hard to get more credible than that. <em>If anyone disagrees with that last statement please state why or correct me instead of down voting.</em> Regardless, standards are merely a suggestion not required; therefore, they should be treated as such. So, I guess as long as you're following <em>some</em> standard then that's good! These are not rules after all.</li> </ul> <p>Nevertheless, markus' solution was good other than the function name (for reasons stated previously). The only thing I would change is the call to <code>Zend_Registry::get()</code> in the <code>_()</code> function. If you plan to call that function as much as you alluded to, then something like this might work better:</p> <pre><code>class MyProject_Controller_Action extends Zend_Controller_Action { /** * the translator object * @var Zend_Translate */ protected $_translator; public function init() { $this-&gt;_translator = Zend_Registry::get('Zend_Translate'); } /** * note my new method name, you don't have to use it but I still * recommend it. the name is just a suggestion, if you prefer something * like _translate() or _trnslte() then by all means (although I don't * recommend abbreviations unless they're super obvious I guess). */ protected function _trans($string) { return $this-&gt;_translator-&gt;translate((string) $string); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload