codeigniter更改语言form_validation_lang [英] codeigniter change language form_validation_lang
问题描述
我尝试在我的hooks文件夹中的LanguageLoader.php中更改form_validation_lang的语言文件,如下所示:
I try to change the language file for my form_validation_lang in my LanguageLoader.php in my hooks folder like this:
class LanguageLoader
{
function initialize() {
$ci =& get_instance();
$ci->load->helper('language');
$siteLang = $ci->session->userdata('site_lang');
if ($siteLang) {
$ci->lang->load('message',$siteLang);
$ci->lang->load('form_validation',$siteLang);
} else {
$ci->lang->load('message','english');
$ci->lang->load('form_validation','english');
}
}
}
对于我的message_lang.php文件,它可以正常工作,但是在更改语言后,codeigniter无法正确加载form_validation_lang.php.
For my message_lang.php file it works fine, but codeigniter does not load the form_validation_lang.php correctly after changing the language.
在我的应用程序文件夹中:
In my application folder:
-语言
-英语
--- message_lang.php
--- form_validation_lang.php
-德语
--- message_lang.php
--- form_validation_lang.php
-language
-- english
---message_lang.php
---form_validation_lang.php
--german
---message_lang.php
---form_validation_lang.php
它始终使用英语形式的form_validation_lang.php文件.当我更改为德语时,它将采用正确的message_lang.php文件,而不是form_validation_lang.php文件.我在做什么错了?
It takes always the form_validation_lang.php file under english. When I change to german it takes the correct message_lang.php file but not the form_validation_lang.php file. What I am doing wrong?
感谢您的帮助!
最诚挚的问候, Yab86
Best regards, Yab86
推荐答案
form_validation的错误消息始终以您在config.php中设置的语言加载.要更改form_validation消息的语言,您需要做一些技巧,像这样更改默认语言:
Error messages for form_validation are always loaded in language you set in your config.php. To change the language for your form_validation messages, you need to do a little trick, changing the default language like this:
$ci->config->set_item('language', $siteLang);
这篇关于codeigniter更改语言form_validation_lang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!