How To Add Multi-Language In CodeIgniter Dynamic

CodeIgniter is an Open Source development framework, which can be used to develop the dynamic application, using PHP. It has a very rich set of hierarchical structures, which will increase the speed of the website and also support security. If you know well PHP coding structure, then CodeIgniter will make your task easier. CodeIgniter provides a rich set of libraries and helpers. By using this framework, you will save a lot of time, if you are developing a website from scratch. CodeIgniter supports a rich set of security as well as has the ability to prevent various unwanted attacks that take place through websites. One great feature of this adds multi-language in the CodeIgniter dynamic.

CodeIgniter framework, multi-language library allow building multiple languages with reliability. If you want to display text in many different languages in CodeIgniter website, then you put different language files in application/language directory. In this article, I will try to explain how to add multi-language in CodeIgniter dynamic.

Creating Language files for multi-language in CodeIgniter

At First, you need to create a language file end it with _lang.php, to configure the key/value before we can start using language support. Add a new language on Arabic language and also store language data with key and value and store in $lang array as shown below code.

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

Loading Language file

Before using any type of the language in your application, first you to load the file of that particular language to retrieve various data stored in that file.

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

filename – It is the name parameter of the file you want to load.

Language – It is the language set where you use.

Autoload multi-language in CodeIgniter

Do you load multi-language automatic, you need to add below code.

Path is application folder / config folder / autoload.php file

$autoload [‘ language ‘] = array();

Step by Step Guide How to Add Multi-Language In Codeigniter Dynamic With Example

First, build a controller class in Lang_controller.php file

path is application folder / controller folder / Lang_controller.php file

class Lang_controller extends CI_Controller {
public function index()
//Load form helper
//Get the selected language
$language = $this->input->post(‘language’);
//Choose language file according to selected lanaguage
if($language == “french”)
else if($language == “german”)
//Fetch the message from language file.
$data[‘msg’] = $this->lang->line(‘msg’);
$data[‘language’] = $language;
//Load the view file

Add a visual file with name lang_view.php and store in this location application folder /views folder /lang_view.php file

This code add in HTML tags

echo form_open(‘/lang’);
<select name=”language” onchange=”javascript:this.form.submit();”>
$lang =
foreach($lang as $key=>$val)
if($key == $language)
echo “<option value=’”.$key.”‘
echo “<option value=’”.$key.”‘>”.$val.”</option>”;
echo $msg;

Add folders with name English in application folder/language folder.

$lang[‘msg’] = “Test Language.”;

ADD file with name eng_lang.php and at end add route parameter in routes.php file.

$route [‘lang’] = “Lang_controller”;

Run code with example ==

We hope this article helped you to understand what is CTE SQL and how to use it. You may also want to see How To Add Multi-Language In CodeIgniter Dynamic.

2 thoughts on “How To Add Multi-Language In CodeIgniter Dynamic”

Leave a Comment

Your email address will not be published. Required fields are marked *