Zend_Translate with dynamic parameters
by Pascal Opitz on March 13 2009, 11:46
Just a quick snippet to have dynamic parameters in the underscore function, without having to write sprintf every time.
<?php
class Translate extends Zend_Translate {
public function _() {
$args = func_get_args();
$num = func_num_args();
$adapter = $this->getAdapter();
$args[0] = $adapter->_($args[0]);
if($num <= 1) {
return $args[0];
}
return call_user_func_array('sprintf', $args);
}
}
Usage would be something like the following:
$t = new Translate('array', $array_translation, $lang);
echo $t->_('My name is %s', 'Pascal');
echo $t->_('I have a %s and a %s', 'Cat', 'Horse');
Comments
by Pascal Opitz on March 18 2009, 15:36 #
by Matthias Willerich on March 13 2009, 20:01 #
I really need to implement this system-wide in the you-know-what application... almost two years later...
by Matthias Willerich on February 21 2011, 13:23 #