我使用CodeIgniter構建多語言Web應用程序。我有/system/languages/
文件夾下的英文和其他語言,並且我創建了一個負責在運行時更改工作語言的模型。表單驗證在運行時更改時忽略語言
默認笨在法國工作作爲/application/config/config.php
$config['language'] = 'french';
後來所定義,根據URI段的模型相應地改變語言,波紋管簡化的示例:
class multilang extends CI_Model {
public function __construct() {
parent::__construct();
if ($this->uri->segment(1) == 'en') {
$this->config->set_item('language', 'english');
}
}
}
這型號是在/application/config/autoload.php
的自動加載設置下列出的第一個型號,我可以確認該語言確實通過調用動態更改:
echo $this->config->item('language');
但是內置的表單驗證庫不考慮改變的語言,而不是隻顯示在設置硬編碼的語言錯誤消息文件/application/config/config.php
在這種情況下,法國。
起初我以爲這是因爲表單驗證在multilang
模型之前加載。爲了確保模型加載第一,我修改了表單驗證構造別的像在此之前加載模型:
public function __construct($rules = array())
{
$this->CI =& get_instance();
$this->CI->load->model('multilang');
// normal code after....
}
這確信表單驗證之前加載模型。不幸的是,這還不夠,表單驗證在運行時更改時仍會忽略語言。任何人都知道這是爲什麼發生?
謝謝。