Codeigniter国际化库如何保存用户的语言选择
我正在使用这个多语言插件 http://codeigniter.com/wiki/CodeIgniter_2.1_internationalization_i18n 来制作在我的 codeigniter 网站上可以使用各种习惯用法。
我有这个带有 echo 链接的 php 代码来更改语言
echo anchor($this->lang->switch_uri('en'),'English | ');
echo anchor($this->lang->switch_uri('es'),'Español | ');
echo anchor($this->lang->switch_uri('ro'),'Română');
它毫无问题地进行了更改,但它不记得了。当我更改页面时,从主页更改为关于页面,如果未定义浏览器语言,将返回浏览器语言或罗马尼亚语。
那么,可能会出现什么问题呢?我应该做什么以及如何记住这个选择?
I am using this multilanguage addon http://codeigniter.com/wiki/CodeIgniter_2.1_internationalization_i18n to make available my codeigniter sites in various idioms.
I have this php code with echo links to change the language
echo anchor($this->lang->switch_uri('en'),'English | ');
echo anchor($this->lang->switch_uri('es'),'Español | ');
echo anchor($this->lang->switch_uri('ro'),'Română');
It does the change with no problem, but it doesn't remember it. When I change page, from home to about, will go back to browser's language or Romanian if browser's language is not defined.
So, what could go wrong? What and how should I do to remember that choice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需使用会话即可更改选择:
$this->session->set_userdata('language', 'en');
查看有关使用 会话数据
稍后通过调用来参考用户的选择:
$language = $this->session->userdata('language ');
You could simply change the choice by using the session:
$this->session->set_userdata('language', 'en');
See more details about using session data
Later refer to what the users choice is by calling:
$language = $this->session->userdata('language ');