Welcome Guest, Not a member yet? Register   Sign In
form_validation language not loading
#1

[eluser]egonr82[/eluser]
Hello,

system: windows 7, wamp server, php 5.3.0 and CI 1.7.2

form_validation library does not change language:

Code:
$this->lang->load('estonian','estonian'):
        $this->load->library('form_validation');
        $this->form_validation->set_rules('username', 'lang:register_username', 'required');

in form_validation.php

Code:
function _translate_fieldname($fieldname)
    {

        // Do we need to translate the field name?
        // We look for the prefix lang: to determine this
        if (substr($fieldname, 0, 5) == 'lang:')
        {
            // Grab the variable
            $line = substr($fieldname, 5);    
            // Were we able to translate the field name?  If not we use $line
            if (FALSE === ($fieldname = $this->CI->lang->line($line)))
            {
                return $line;
            }
        }

        return $fieldname;
    }

fragment:

Code:
$this->CI->lang->line($line)

returns nothing

estonian_lang.php includes:

Code:
$lang['register_username'] = 'Soovitud kasutajanimi';

functions like
Code:
lang('register_username');
inside views are working


why i cant change language for errors?
#2

[eluser]imn.codeartist[/eluser]
to change your system error message in your local language

go to the system/language folder and add new folder of your language

copy all the files from the system/language/english into system/language/yourlanguage

open all files from system/language/yourlanguage and change the message according to your language.

It should solve your problem.

Dixanta Shrestha
[email protected]
#3

[eluser]egonr82[/eluser]
thnx, i got it loading wrong language file.

I have header view where i call function to set language:
Code:
function set_lang()
    {
    
        if ($lang = $this->session->userdata('lang'))
        {
            $this->lang->load($lang,$lang);
            
        }
        else
        {
            $this->lang->load('estonian', 'estonian');
        }
    }

so default is estonian. I also have change language function:

Code:
function lang()
    {
        $lang = $this->uri->segment(3);
        
        //We use the function from the auth
        if ($lang == 'english' or $lang == 'estonian')
        {
             if($this->auth->is_logged_in())
            {
                $this->db->where('id', $this->session->userdata('user_id'));
                $this->db->update('users',array('lang' => $lang));
                  
            }
             $this->session->set_userdata('lang',$lang);
        }
        redirect('/');
    }


this doesnt do the trick for me. form_validation still uses english for variables and error messages. If my form validation function looks like this:
Code:
$this->lang->load('estonian','estonian');
       $this->load->library('form_validation');

i get variables in estonian, but error messages in english. If i try to autoload ($autoload['language'] = array('english', 'estonian')Wink estonian i get error like this:
Unable to load the requested language file: language/english/estonian_lang.php

PS! Both language folders are in place

/system/languages/estonian - form_validation_lang.php with edited messages
/system/application/estonian/ - estonian_lang.php with mentioned variable


so what is the right way for setting and changing languages in allover system? I dont even understand why there is two language folders needed??
#4

[eluser]egonr82[/eluser]
so is this bug or not??? that it does not load estonian error messages from ./system/language/estonian/form_validation_lang.php

?
#5

[eluser]imn.codeartist[/eluser]
its not a bug as mine works perfectly fine.

there should be some problem u ur coding please place all the codes
#6

[eluser]egonr82[/eluser]
i made test controller for this:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Form extends Controller {

    function Form()
    {
        parent::Controller();
        
    }
    
    function index()
    {
        $this->load->view('form');    
    }
    function validate()
    {
        $this->lang->load('estonian','estonian');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('username', 'lang:username', 'required');
        $this->form_validation->run();
        $this->load->view('form');        
    }
}

test view for this:

Code:
<?php
echo validation_errors();
echo form_open('form/validate');
?>
<input type="text" name="username">
<input type="submit">
<?php
echo form_close();
?>

this outputs:

The Kasutajanimi field is required. Kasutajanimi is right and is from ./system/application/language/estonian_lang.php

Code:
$lang['username'] = 'Kasutajanimi';

But error message should be "Kasutajanimi on nõutud." as stated in ./system/language/estonian/form_validation_lang.php

Code:
$lang['required']             = "%s on nõutud.";

my config file:

Code:
$config['language']    = "english";

my autload file:

Code:
$autoload['language'] = array();

i in troubleSmile help me out please.
#7

[eluser]imn.codeartist[/eluser]
since, there is still english at ur config. the error messages are displaying in english
#8

[eluser]imn.codeartist[/eluser]
[quote author="dixcoder" date="1254467000"]since, there is still english at ur config. the error messages are displaying in english[/quote]

I have made bit modification in your controller.


Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Form extends Controller {

    function Form()
    {
        parent::Controller();
        $this->config->set_item('language','estonian');//New added line
        
    }
    
    function index()
    {
        $this->load->view('form');    
    }
    function validate()
    {
        $this->lang->load('estonian','estonian');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('username', 'lang:username', 'required');
        $this->form_validation->run();
        $this->load->view('form');        
    }
}
#9

[eluser]egonr82[/eluser]
thnx, that did the job.




Theme © iAndrew 2016 - Forum software by © MyBB