Welcome Guest, Not a member yet? Register   Sign In
Form Validation and language selection
#1

[eluser]Adam K[/eluser]
Hello,

I'm using my own simple language selection through my app in CI, however I use Form Validation Class for validating forms.

This is my only controller:

Code:
<?php

class Site extends Controller {

    var $data;

    function Site()
    {
        parent::Controller();    
        
        define("SK",'sk');
        define("EN",'en');
        
        //load site XML
        $this->data = array('x'=>simplexml_load_file('data/content/site.xml'));
    }

    function _set_language($lang){
        define('LANG',$lang);
    }
    
    function index($lang='sk'){
        $this->_set_language($lang);
    }

    function _sluzby($lang){
        $this->_set_language($lang);    
    }
    
    function _referencie($lang, $projekt=null){
        $this->_set_language($lang);
    }
    
    function _postup($lang){
        $this->_set_language($lang);
    }
    
    function _kontakt($lang){
        $this->_set_language($lang);    
    }
    
    /* SLOVENCINA */
        function sluzby(){ $this->_sluzby(SK); }
        function referencie($projekt=null){ $this->_referencie(SK,$projekt); }
        function ako_pracujeme(){ $this->_postup(SK); }
        function kontakt() { $this->_kontakt(SK); }
    
    /* ANGLICTINA */
        function services(){ $this->_sluzby(EN); }
        function work($projekt=null){ $this->_referencie(EN,$projekt); }
        function the_process(){ $this->_postup(EN); }
        function contact(){ $this->_kontakt(EN); }
}

/* End of file site.php */
/* Location: ./system/application/controllers/site.php */

as you can see, it's rather straightforward, defining LANG allows me later in templates decide which part of html to show with easily readable

Code:
if(LANG===SK)

My problem however is with translated form validation errors - I can't find out how to tell CI which language to use Run Time, since I set language application-wide BEFORE any controller method kicks in (I use just form validation lang files)




Theme © iAndrew 2016 - Forum software by © MyBB