Welcome Guest, Not a member yet? Register   Sign In
language file
#1

[eluser]hamzakhan[/eluser]
how we can dynamically load and change language files using codeigniter.
i am using 3 languages on my site user cn switch to any language.as they like
any best logic or idea to do this.
#2

[eluser]Ener1[/eluser]
Hi,

Im currently using something like this

in the constructor of your controllers

Code:
if(!isset($this->session->userdata['lng'])||$this->session->userdata['lng']=='')
{
    $this->session->userdata['lng']='es';
}

Then I have a method called CL(change language)
Code:
function cl($lan,$actual)
    {
            
             $actua = str_replace('-','/',$actual);
               $this->lng=$lan;
             $this->session->set_userdata(array('lng'=>$this->lng));
            redirect(base_url().$actua, 'refresh');

    }

And from the views

Code:
<a href="&lt;?php echo base_url(); ?&gt;home/cl/es/&lt;?php echo $actual;?&gt;">lang->line('es')?&gt;" class="idioma">
            <img src="&lt;?php echo base_url();?&gt;images/img_sitio/es.jpg"  alt="Espa&ntilde;ol" /> Espa&ntilde;ol
</a>
<a href="&lt;?php echo base_url(); ?&gt;home/cl/en/&lt;?php echo $actual;?&gt;">lang->line('en')?&gt;"   class="idioma">
            <img src="&lt;?php echo base_url();?&gt;images/img_sitio/en.jpg"  alt="English" /> English
</a>

Plus you can just put your static text in the language arrays ( for this just follow the CI user guide ), and in that array the actual language. So you have it everywhere. Example:

Code:
&lt;?php
//idiomas estilo destacado
$lang['en'] = "text-decoration:underline;";
$lang['es'] = "text-decoration:none;";
$lang['frase'] = "Quote";
$lang['idioma'] = "Language";
$lang['bienvenida'] = "Welcome";
$lang['noticias'] = "News";



and in my Database I also have an language field, so I can put dynamic data in multiple langages too.

I hope this helps




Theme © iAndrew 2016 - Forum software by © MyBB