In this tutorial you will learn about CodeIgniter Internationalization.  The CodeIgniter language class offers an easy way to support multiple languages for internationalization. To a certain extent we can display text in many different languages using different language files.

We can place different language files in the language/application directory. System language files can be found in the system/language directory but you should create a separate folder for each language in the application/language directory in order to add your own language to your application.

Creating CodeIgniter Language File

You must finish with lang.php to create a language file. For instance, you want to create a French language file, then you need to save it with french_lang.php file. In this file, you can save all your language texts in $lang array as shown below.

$lang[‘key’] = ‘val’;

Loading CodeIgniter Language File

In order to use any of the languages in your application, you must first load the file in that particular language to get different texts in that file. You can load the language file using the following code.

$this->lang->load('filename', 'language');
  • filename − It’s the file name you want to load. Do not use file extension here, but only file name.
  • Language − It’s the set of languages.

Fetching Language Text

Simply execute the following code to get a line from the language file.


Where language key is the key parameter used in the loaded language file to get the value of the key.

Autoload CodeIgniter Languages

If you need a global language, you can automatically load it into application/config/autoload.php as shown below.

| -----------------------------------------------------------------------
|  Auto-load Language files
| -----------------------------------------------------------------------
| Prototype:
|   $autoload['language'] = array('lang1', 'lang2');
| NOTE: Do not include the "_lang" part of your file. For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
$autoload['language'] = array();

Pass the various languages to be auto-loaded by CodeIgniter.

Subscribe to our newsletter

You can unsubscribe anytime you want