Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...