Finally, I got success to make several languages
follow these steps
MY_Lang.php file in folder application\core
MY_Lang.php
<?php
(defined('BASEPATH')) OR exit('No direct script access allowed');
class MY_Lang extends CI_Lang
{
function __construct() {
global $URI, $CFG, $IN;
$config =& $CFG->config;
$index_page = $config['index_page'];
$lang_ignore = $config['lang_ignore'];
$default_abbr = $config['language_abbr'];
$lang_uri_abbr = $config['lang_uri_abbr'];
$uri_abbr = $URI->segment(1);
$URI->uri_string = preg_replace("|^\/?|", '/', $URI->uri_string);
if ($lang_ignore) {
if (isset($lang_uri_abbr[$uri_abbr])) {
$IN->set_cookie('user_lang', $uri_abbr, $config['sess_expiration']);
} else {
$lang_abbr = $IN->cookie($config['cookie_prefix'].'user_lang');
}
if (strlen($uri_abbr) == 2) {
$index_page .= empty($index_page) ? '' : '/';
$URI->uri_string = preg_replace("|^\/?$uri_abbr\/?|", '', $URI->uri_string);
header('Location: '.$config['base_url'].$index_page.$URI->uri_string);
exit;
}
} else {
$lang_abbr = $uri_abbr;
}
if (isset($lang_uri_abbr[$lang_abbr])) {
$URI->uri_string = preg_replace("|^\/?$lang_abbr|", '', $URI->uri_string);
$config['language'] = $lang_uri_abbr[$lang_abbr];
$config['language_abbr'] = $lang_abbr;
if ( ! $lang_ignore) {
$index_page .= empty($index_page) ? $lang_abbr : "/$lang_abbr";
$config['index_page'] = $index_page;
}
$IN->set_cookie('user_lang', $lang_abbr, $config['sess_expiration']);
} else {
if ( ! $lang_ignore) {
$index_page .= empty($index_page) ? $default_abbr : "/$default_abbr";
if (strlen($lang_abbr) == 2) {
$URI->uri_string = preg_replace("|^\/?$lang_abbr|", '', $URI->uri_string);
}
$q = $_SERVER['QUERY_STRING'];
if($q)
$q = "/?".$q;
header('Location: '.$config['base_url'].$index_page.$URI->uri_string.$q);
exit;
}
$IN->set_cookie('user_lang', $default_abbr, $config['sess_expiration']);
}
log_message('debug', "Language_Identifier Class Initialized");
}
}
function t($line) {
global $LANG;
return ($t = $LANG->line($line)) ? $t : $line;
}
function _t($line,$params=array()) {
global $LANG;
if($params){
echo str_replace(array_keys($params),array_values($params),($t = $LANG->line($line)) ? $t : $line);
}
else
echo ($t = $LANG->line($line)) ? $t : $line;
} ?>
and added below in config.php
$config['language'] = "english";
$config['language_abbr'] = "en";
$config['lang_uri_abbr'] = array("en" => "english","es" => "spanish","ca" => "catalan");
$config['lang_ignore'] = TRUE;
route.php
$route['^en/(.+)$'] = "$1";
$route['^es/(.+)$'] = "$1";
$route['^ca/(.+)$'] = "$1";
$route['^(\w{2})$'] = $route['default_controller'];
$route['^(\w{2})/(.+)$'] = "$2";
,
language/catalan
language/spanish
language/english
, .