Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoload language codeigniter

making a multi-language site with codeginiter. I have created two folders. One for french language files and one for english. When I go to autoload the languages (English and French) as such

($autoload['language'] = array('en', 'fr');)

I get an error "Unable to load the requested language file: language/english/fr_lang.php"

How can I get it to look in the proper folder?

Thanks

like image 587
JonYork Avatar asked Feb 16 '12 17:02

JonYork


People also ask

What is autoload in CodeIgniter?

CodeIgniter comes with an “Auto-load” feature that permits libraries, helpers, and models to be initialized automatically every time the system runs. If you need certain resources globally throughout your application you should consider auto-loading them for convenience.

How to autoload database in CodeIgniter?

Go ahead and open up the autoload configuration file — application/config/autoload. php — locate the $autoload['libraries'] setting, and alter it to auto-load the database library, as shown here: . . . $autoload['libraries'] = array('database'); . . .


1 Answers

$config['language']

is the default folder used for loading language files, which is why your

fr_lang.php

is loaded from there.

Either change the value of:

$config['language']

when needed, like:

$this->config->set_item('language', 'value');

(Remember this has to be done before the languages load, so you would use a hook for that http://codeigniter.com/user_guide/general/hooks.html.)

Or else, load your language files on the fly:

$this->lang->load('filename', 'language');

You should definitely check out the core classes to get a better understanding of how things work. You can browse the code easily here: https://github.com/EllisLab/CodeIgniter For instance, the languages are loaded with this class: https://github.com/EllisLab/CodeIgniter/blob/develop/system/core/Lang.php

If you need any more help, let me know.

like image 75
conradkleinespel Avatar answered Sep 28 '22 09:09

conradkleinespel