Skip to content

Develop Multilingual site using codeigniter i18n Library

CodeIgniter has lot of Useful helper functions and libraries , Classes. Here we are going to Develop a Multilingual Site Using CodeIniger Language Class and i18n Library.

I am assuming that you know basic installation of CI application, if no please have look on CodeIgniter Tutorials

How it works:

example.com/en/contact/
example.com/de/contact/
example.com/fr/contact/

codeIgniter Localization steps :

We are going to put our language files in Language folder which located at (application/language/).

In our application we have three languages English, French, german

In each folder we have file having name contact_lang.php contains respective languages text.

It has simple syntax:

$lang['language_key'] = "The actual text to be shown";

Our english/contact_lang.php has code as follows;

 $lang['page_title'] = "Contact Us";

We need to make same files as per required languages. Just we have to write right side part in required language.

installation:

Download: here
Put MY_Language.php and MY_Config.php in application/core
Put MY_language_helper.php in application/helpers/

Configuration :

You must be using pretty URLs (without index.php). With Apache it’s usually achieved with mod_rewrite through an .htacess

In config.php

$config[‘base_url’] must correspond to your configuration.

$config[‘index_page’] = “”

In routes Add Fallowing :

// URI like '/en/about' -> use controller 'about'
$route['^(en|de|fr)/(.+)$'] = "$2";

// '/en', '/de', '/fr'  URIs -> use default controller
$route['^(en|de|fr)$'] = $route['default_controller'];

Now Create your Controller :

load->helper(array('url','html'));
		$this->load->helper('language');  
		$this->lang->load('contact');
		$this->_render('pages/contact');
	}
}

/* End of file Contact.php */
/* Location: ./application/controllers/contact.php */

Final Step Create your view :


0 0 votes
Article Rating
Subscribe
Notify of
guest

3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments