I have been wondering this for a while. Take this example:
<?= Zend_Registry::get('translate')->_('translate me!');
I have my views cluttured with such code. My coworkers also complain often that its a lot to type juste to get translation and since it is repeated all over the place it gets tedious.
Some of them would love some global function that wraps everything in a short name like:
function t($text){
return Zend_Registry::get('translate')->_($text);
}
But to me this is not good design and kinda defeats the idea of putting my translation object in the registry.
So I was wondering what others do to avoid having to write all this unnecessary code.
One solution would be to do in my controller:
$this->view->t = Zend_Registry::get('translate);
and then in my view just:
<?= $this->t('translate me!'); ?>
Another would be to create a view helper that does the job:
<?= this->translate('translate me!');?>
But it is more work and again adds a layer of logic on top of the already pretty robust and straigthforward Zend_Registry+ZendTranslate.
If you use the default setup method for translate you can use the following code inside your view scripts:
<?= $this->translate('TEXT_SETUP_HELP_SERVERNAME'); ?>
or even shorter:
<?= $this->_('TEXT_SETUP_HELP_SERVERNAME'); ?>
Example from application.ini:
; Setup Zend_Translate
resources.translate.registry_key = "Zend_Translate"
resources.translate.adapter = "array"
resources.translate.options.logUntranslated = false
resources.translate.options.scan = "filename"
resources.translate.options.disableNotices = 0
resources.translate.data = APPLICATION_PATH "/languages"
resources.translate.locale = "en_EN"