我有/ language / english和/ language / french
这个法国人 $ lang ['user_login'] ='Connecté';
这个英语 $ lang ['user_login'] ='登录';语言文件名为user_lang.php
控制器构造函数上的我有:
$this->load->helper('url');
$this->load->helper('language');
关于函数索引我有这个:
public function index()
{
$this->lang->load('user', 'french');
...
在视图上我有以下内容:
<div class="pageTitle"><?php echo $this->lang->line('user_login');?></div>
/*
| -------------------------------------------------------------------
| Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file. For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/
$autoload['language'] = array('user');
问题是该网站正在使用user_lang.php 得到登录
这个词但只转到英文文件
$this->lang->load('user', 'french');
iam正在执行上述操作,并且它无法正常读取法语文件
我有另一个问题,我怎样才能使这个工作,所以我可以用锚或href切换语言
感谢 佩德罗
答案 0 :(得分:1)
我会创建一个像:
这样的函数function language($language){
$language = urldecode($language);
switch($language){
case "French":
$this->session->set_userdata('lang_id', 2);
$this->session->set_userdata('lang_name', 'french');
redirect('/', 'refresh');
break;
case "Russian":
$this->session->set_userdata('lang_id', 3);
$this->session->set_userdata('lang_name', 'russian');
redirect('/', 'refresh');
break;
default: //default is English
$this->session->set_userdata('lang_id', 1);
$this->session->set_userdata('lang_name', 'english');
redirect('/', 'refresh');
break;
}
}
我会更改导航到http://www.domain.com/controller/language/French
的语言然后在每个控制器或每个控制器类的构造函数中,我将检查lang_id和lang_name会话。如果设置了会话,我会使用它们。否则配置中的默认语言将自动加载。例如:
$lang = $this->session->userdata('lang_name');
if(!isset($lang)){ //load default language
$this->lang->load('home');
$data = array(
'title' => lang('page_title')
);
//etc etc
}else{ //load language from session
$this->lang->load('home', $this->session->userdata('lang_name'));
$data = array(
'title' => lang('page_title')
);
//etc etc
}
答案 1 :(得分:0)
在我的欢迎控制器中
public function french()
{
$this->session->set_userdata('lang_id', 2);
$this->session->set_userdata('lang_name', 'french');
$DContent['page_details'] = array('page_title' => 'Index of onplans');
$Dheader = array();
$Dsidebar = array();
$Dfooter = array();
$Dmeta = array('meta_title'=>'Welcome to onplans','meta_descricao'=>'onplans');
$this->template->write_view('meta', 'html/meta', $Dmeta, true);
$this->template->write_view('header', 'html/header', $Dheader, true);
$this->template->write_view('content', 'onplans/frenchset', $DContent,true);
$this->template->write_view('sidebar', 'html/sidebar');
$this->template->write_view('footer', 'html/footer');
$this->template->render();
}
public function english()
{
$this->session->set_userdata('lang_id', 3);
$this->session->set_userdata('lang_name', 'english');
$DContent['page_details'] = array('page_title' => 'Index of onplans');
$Dheader = array();
$Dsidebar = array();
$Dfooter = array();
$Dmeta = array('meta_title'=>'Welcome to onplans','meta_descricao'=>'onplans');
$this->template->write_view('meta', 'html/meta', $Dmeta, true);
$this->template->write_view('header', 'html/header', $Dheader, true);
$this->template->write_view('content', 'onplans/englishset', $DContent,true);
$this->template->write_view('sidebar', 'html/sidebar');
$this->template->write_view('footer', 'html/footer');
$this->template->render();
}
名为user 的目标控制器上的
$this->load->helper('url');
$this->load->helper('language');
print_r('lang_session'.$this->session->userdata('lang_name'));
$lang = $this->session->userdata('lang_name');
if(!isset($lang)){ //load default language
$this->lang->load('user');
}else{ //load language from session
print_r('lang :'.$this->session->userdata('lang_name'));
$this->lang->load('user',$this->session->userdata('lang_name')); //);
}
现在正在运作