codeigniter_tutorial
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
23. Internationalization<br />
CodeIgniter<br />
The language class in CodeIgniter provides an easy way to support multiple languages<br />
for internationalization. To some extent, we can use different language files to display<br />
text in many different languages.<br />
We can put different language files in application/language directory. System language<br />
files can be found at system/language directory, but to add your own language to your<br />
application, you should create a separate folder for each language in<br />
application/language directory.<br />
Creating Language files<br />
To create a language file, you must end it with _lang.php. For example, you want to<br />
create a language file for French language, then you must save it with<br />
french_lang.php. Within this file you can store all your language texts in key, value<br />
combination in $lang array as shown below.<br />
$lang[‘key’] = ‘val’;<br />
Loading Language file<br />
To use any of the language in your application, you must first load the file of that<br />
particular language to retrieve various texts stored in that file. You can use the following<br />
code to load the language file.<br />
$this->lang->load('filename', 'language');<br />
<br />
<br />
filename – It is the name of file you want to load. Don’t use extension of file<br />
here but only name of file.<br />
Language – It is the language set containing it.<br />
Fetching Language Text<br />
To fetch a line from the language file simply execute the following code.<br />
$this->lang->line('language_key');<br />
Where language_key is the key parameter used to fetch value of the key in the loaded<br />
language file.<br />
Autoload Languages<br />
If you need some language globally, then you can autoload it in<br />
application/config/autoload.php file as shown below.<br />
83