1
使用Zend Framework時很容易to log strings that haven't got a translation。使用Zend_Translate時的日誌翻譯字符串
我的問題:你如何記錄有翻譯的字符串?
謝謝!
使用Zend Framework時很容易to log strings that haven't got a translation。使用Zend_Translate時的日誌翻譯字符串
我的問題:你如何記錄有翻譯的字符串?
謝謝!
沒有能力在Zend_Translate中記錄translate()調用,但是您可以創建自己的幫助程序,將所有對原始translate()助手的調用進行代理並將其用於您的需要。
這裏是helper方法的一些例子:
/**
* 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);
代替那麼你可以添加任何自定義功能,該方法記錄您需要的信息。
這個解決方案不是很快,但可以讓你做到這一點。
我創建了這個方法試圖解決此問題:
您可能需要延長用於翻譯類,調用'parent'方法,然後登錄你的成功轉換。 – 2010-09-15 08:13:39