【发布时间】:2010-09-15 07:23:55
【问题描述】:
【问题讨论】:
-
您可能需要扩展用于翻译的类,调用
parent方法,然后记录您的成功翻译。
标签: php zend-framework zend-translate zend-log
【问题讨论】:
parent 方法,然后记录您的成功翻译。
标签: php zend-framework zend-translate zend-log
在 Zend_Translate 中无法记录 translate() 调用,但您可以创建自己的助手,它将代理所有对原始 translate() 助手的调用并将其用于您的需要。
这里是一些辅助方法的例子:
/**
* Translates provided message Id
*
* You can give multiple params or an array of params.
* If you want to output another locale just set it as last single parameter
* Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale);
* Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale);
*
* @param string $messageid Id of the message to be translated
* @return string Translated message
*/
public function t_($messageid = null)
{
/**
* Process the arguments
*/
$options = func_get_args();
array_shift($options);
$count = count($options);
$locale = null;
if ($count > 0) {
if (Zend_Locale::isLocale($options[($count - 1)], null, false) !== false) {
$locale = array_pop($options);
}
}
if ((count($options) === 1) and (is_array($options[0]) === true)) {
$options = $options[0];
}
/**
* Get Zend_Translate_Adapter
*/
$translator = $this->translate() // get Zend_View_Helper_Translate
->getTranslator(); // Get Zend_Translate_Adapter
/**
* Proxify the call to Zend_Translate_Adapter
*/
$message = $translator->translate($messageid, $locale);
/**
* If no any options provided then just return message
*/
if ($count === 0) {
return $message;
}
/**
* Apply options in case we have them
*/
return vsprintf($message, $options);
}
并像这样使用它:
echo $this->t_('message-id', $param1, $param2);
而不是
echo $this->translate('message-id', $param1, $param2);
然后您可以向该方法添加任何自定义功能来记录您需要的信息。
这个解决方案不是很快,但可以让你做到这一点。
我在尝试解决此问题时创建了此方法:
【讨论】: