2010-09-15 24 views

回答

0

沒有能力在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); 

代替那麼你可以添加任何自定義功能,該方法記錄您需要的信息。

這個解決方案不是很快,但可以讓你做到這一點。

我創建了這個方法試圖解決此問題:

http://framework.zend.com/issues/browse/ZF-5547