2013-11-01 17 views

回答

0

不寫第二個參數。保持空着。

0

看看郎功能(發現地:/system/helpers/language_helper.php):

function lang($line, $for = '', $attributes = array()) 
    { 
      $CI =& get_instance(); 
      $line = $CI->lang->line($line); 

      if ($for !== '') 
      { 
        $line = '<label for="'.$for.'"'._stringify_attributes($attributes).'>'.$line.'</label>'; 
      } 

      return $line; 
    } 

正如你可以看到它需要3個參數。第一個參數是必需的,但後兩個是可選的。如果你聲明第二個參數,它將返回包裝在標籤中的語言字符串。

因此,說明只有第一個參數應使其輸出只是語言字符串。


UPDATE:

從閱讀您的評論聽起來好像你會更好使用language class直接。然而,僅僅語言課程還不夠,你需要爲了你的目的而擴展它。爲此,您可以在名爲MY_lang.phpapplication/core文件夾中創建一個新文件。

class MY_Lang extends CI_Lang { 

    // You want to extend the line function 
    function line($line = '', $value = '') 
    { 
      $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; 

      // We can assume that if a value is passed it is intended to be inserted into the language string 
      if($value) { 
        $line = sprintf($line, $value); 
      } 

      // Because killer robots like unicorns! 
      if ($line === FALSE) 
      { 
        log_message('error', 'Could not find the language line "'.$line.'"'); 
      } 

      return $line ; 
    } 
} 

假設你的語言文件有一個字符串,像這樣:

$name = "foo"; 
$this->lang->line('welcome_text', $name); 

以上:

$lang['welcome_text'] = "Welcome %s"; 

然後,您可以通過加載語言類,並使用下面的代碼中使用此是100%未經測試的,所以它可能需要一些tweeking,但它應該給你一個開始的地方。

+0

感謝您的回答。事情是我需要添加第二秒,因爲Im使用以下類型的「歡迎%s」,其中%s是名稱的動態值。和代碼像'lang('welcome_text',$ name);'我最好的選擇是去一個自定義的功能? – JohnSmith