CodeIgniter Forums
language file - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Libraries & Helpers (
+--- Thread: language file (/thread-31274.html)

language file - El Forum - 06-12-2010

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

language file - El Forum - 06-18-2010


Im currently using something like this

in the constructor of your controllers


Then I have a method called CL(change language)
function cl($lan,$actual)
             $actua = str_replace('-','/',$actual);
            redirect(base_url().$actua, 'refresh');


And from the views

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

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:

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