yab86 yab86 - 7 months ago 125
PHP Question

codeigniter change language 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');
}
}
}


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:

-language

-- english

---message_lang.php

---form_validation_lang.php

--german

---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?

Thanks for your help!

Best regards,
Yab86

Answer

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); 
Comments