Internationalization (i18n) library for CodeIgniter 2

What it does

Language in URL:


Keep using CodeIgniter Language Class




English language file

$lang['about.gender'] = "I'm a man";

French language file

$lang['about.gender'] = "Je suis un homme";

Result with

<p>I'm a man</p>

Result with

<p>Je suis un homme</p>



In application/config/routes.php add

// example: '/en/about' -> use controller 'about'
$route['^fr/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";
// '/en' and '/fr' -> use default controller
$route['^fr$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];


Let's build a bilingual English/French page.

language files


$lang['about.gender'] = "I'm a man";
/* End of file */


$lang['about.gender'] = "Je suis un homme";
/* End of file */



class About extends CI_Controller {
	function index()
		// you might want to just autoload these two helpers
		// load language file
/* End of file */



<p><?=anchor('music','Shania Twain')?></p>



<p>I'm a man</p>
<p><a href="">Shania Twain</a></p>


<p>Je suis un homme</p>
<p><a href="">Shania Twain</a></p>


  • You might need to translate some of CodeIgniter's language files in system/language. Example: if you're using the “Form Validation” library for French pages, translate system/language/form_validation_lang.php to application/language/french/form_validation_lang.php.
  • links to internal pages are prefixed by the current language, but links to files are not.
  • Get the current language
// en
  • Switch to another language
anchor($this->lang->switch_uri('fr'),'Display current page in French');
  • the root page (/) is supposed to be some kind of splash page, without any specific language. This can be changed: see “No splash page” below.

How it works

MY_Config.php contains an override of site_url(): add language segment (when appropriate) to generated URLs. Also used by anchor(), form_open()...


Special URIs

A special URI is not prefixed by a language. The root URI (/) is by default a special URI.

You might need other special URIs, like for an admin section in just one language.

In application/core/MY_Lang.php, add admin to the $special array. Now, links to admin won't be prefixed by the current language.


No splash page

In application/core/MY_Lang.php

  • remove ”” from the $special array
  • set $default_uri to something else like home
  • now a request to / will be redirected to en/home, if English is your default language
  • the default language is the first item of the $languages array

Add a new language

  • application/core/MY_Lang.php: add new language to $languages array
// example: German (de)
'de' => 'german',
  • application/config/routes.php: add new routes
// example: German (de)
$route['^de/(.+)$'] = "$1"; 
$route['^de$'] = $route['default_controller'];
  • create corresponding language folder in application/language. For this “German” example, it would be called german.


This April 15, 2009 update fixes the issues reported before:

- Mark: autoloading of language files wasn't working

- François: language segment was sometimes added to a link when there was already one

- Frank: it wasn't possible to use the library methods in a controller's constructor

Thank you all for your feedback.
Jérôme Jaglale
Apr 15, 2009
Thanks Jerome, get an error and not sure why, simply replaced the old files with new ones, changed the MY to FW as I had before when all was fine. Fatal error: Call to undefined method FW_Language::init_language() in W:\www\s\system\libraries\Hooks.php on line 205
Apr 16, 2009
BS, please remove the hook in config/hooks.php, it's not needed anymore.
Jérôme Jaglale
Apr 16, 2009
When I try to switch to /es/ I get this error: Unable to load the requested language file: language/profiler_lang.php There is no file by that name, and language folder is setup the same as worked with previous version... what did I miss this time? :) thanks a million!
Apr 16, 2009
Oops, i forgot to mention, this breaks scaffolding links (edit/add/etc), were you aware? I can send you a link to show you what I'm talking about via email rjdjohnston(at)gmail(dot)com if you like.
Apr 16, 2009
Started a thread on my error from switch from en to es, see here: Dank je!

Apr 17, 2009
This April 17, 2009 update fixes the issues reported before:

- BS: scaffolding wasn't working
- Dan: wrong URL generated with form_open(), redirection bugs

If you've been using a previous version, make sure to remove helpers/MY_url_helper.

Note from Dan:
For people using dx_auth module they will need to edit the config file (system/application/config/dx_auth.php) at line 188 onwards there are some variable definitions e.g. $config['DX_deny_uri'] = '/auth/deny/'; It is best to remove the leading / e.g. $config['DX_deny_uri'] = 'auth/deny/'; otherwise when a user is redirected to the login form the url comes up as http://idm.ts/en//auth/login - this does actually display the right page and doesnt affect it but just to make it look professional!

Thank you for your feedback.
Jérôme Jaglale
Apr 17, 2009
This April 20, 2009 update fixes a bug: the redirection wasn't working when the language in the URL was wrong.
Jérôme Jaglale
Apr 20, 2009
Thank you very much for this very useful library! Saved me a ton of work.
Jeroen van der Gulik
May 18, 2009
Thanks a lot, it's excellent !
May 20, 2009
I've just modified a line in MY_language.php If the URI doesn't content language information, i'm loading the page asking with the default language. I don't use the default uri anymore Code: header("Location: " . $CFG->site_url($this->lang($this->languages[$this->default_lang()]).'/'.$segment), TRUE, 302);
May 20, 2009
is this library work with ocular layout library? thx..
Jul 15, 2009
Thanks a lot, great work. I discovered small bug in MY_Language: If var $special = array (""); - this array is empty, the function is_special() doesn't work as expected because even empty the URL is treated as special
Martin Rusev
Aug 6, 2009
Thanks Jérôme, great script! Is there a way I could translate the links too? Example: English url: en/about French url: fr/propos Both URLs routed to the about.php controller where the language strings returned according to the langugae. This would highly increase the search-engine friendlyness of the script. I'm trying to find a solution, but I'm a beginner...
Aug 15, 2009
Amazing, you saved my life bud!!!
Aug 20, 2009
Just integrated with CI with HMVC, worked fine till now. :)
Mahbubur Rahman
Aug 24, 2009
Very nice. It's possible to remove the language from the URI ?
Aug 25, 2009
Ed: no, the goal here is actually to rely on the language in the URI: so we don't need to set a cookie on the client browser or use the HTTP headers sent by the browser. Also the page will be referenced by search engines in both languages.
Jérôme Jaglale
Aug 25, 2009
this looks very good... I will try it out merci beaucoup Jerome...
Aug 26, 2009
Hi, just to mention that it worked like a charm... indeed saved me hours of work :-) thanks a lot
Aug 26, 2009
So i had to drop the HMVC with i18n library. Views in folders don't seem to work easily. Need to change a lot in router to get HMVC+i18n to work. So I'm back without HMVC because i18n was the main need.
Mahbubur Rahman
Aug 31, 2009
great work man!!
Leandro Gilioli
Sep 18, 2009
This is great! Really usefull!
Sep 18, 2009
very great lib, but I need also HMVC to work, any suggestions? another thing, redirect default language is nice but if you type /controllername/functionname it does not redirect to let's say /en/controllername/functionname
Oct 17, 2009
This is all fine and dandy, but having to manually write all the routes is not all that useful. Plus, if you are trying to make a multilingual site, you do not want the URIs to be in english:


It should be like this:

Ideally this would work by either checking your database to find the uri, or have the system dynamically generate the routing config file.

That's my two cents worth.
Peter Hebert
Oct 22, 2009
Peter, what do you mean by "having to manually write all the routes"? It's only two routes for each language.

I agree about the localized URLs, that should be an option. I got something working on a project, but it's too much of a hack. I have yet to come with a better solution. Thanks for the feedaback!
Jérôme Jaglale
Oct 22, 2009
I mean that if you want to call your controller/function by the appropriate name in each language, you would need to write a route for each of them:

ie. if your controller is 'about', and the function is 'men', then you would need two routes if you wanted to call it in english, french, and spanish:

$route['a-propos/hommes'] = "about/men";
$route['acerca/hombres'] = "about/men";

The same would apply for every controller and function.
Peter Hebert
Oct 27, 2009
Ok, you were already talking about the localization of the URLs..

But you would have to declare them somewhere anyway, routes.php or database, no?

I don't see how you could generate that, especially if you use parameters with the functions: store/buy/chocolat_blanc -> store/buy/white_chocolate

Any ideas?
Jérôme Jaglale
Oct 27, 2009
Great work, i have a question How can i load a different language from the controller? I have to send an email to the user which has a different preffered language than the admin, how can i load the translation for the user ? Thank you!
Cristian Boboc
Nov 3, 2009
Automatic configuration for ci_I18n library

//create config/supported_lang.php file
$config [ 'supported_lang'] =
array (
'en' => 'Spanish',
'in' => 'English',
'gl' => 'Galician',
'ca' => 'catalan',
'ja' => 'japanese',
'de' => 'Dutch',

//in libraries/MY_Language.php

replace var $languages= array(...)
like this var $languages;

in the class constructor
global $CFG;
$this->languages = $CFG->item ( 'supported_lang');

//in config/routes.php
global $CFG;

//Load the config file
$CFG->load( 'supported_lang');

//browser language
$browser_lang = strtolower (substr ($_SERVER ["HTTP_ACCEPT_LANGUAGE"], 0.2));
//if supported
$CFG->set_item('language', $CFG->item($browser_lang,'supported_lang'));

$route['default_controller'] = "my_default_controller";
$route['scaffolding_trigger'] = "";
foreach($CFG->item('supported_lang') as $lang => $value)
$route["^$lang/(.+)$"] = "$1";

$route["^$lang\$"] = $route['default_controller'];


I want them to be useful
Jérôme Jaglale thank for their fantastic
library and sorry for my English
Nov 3, 2009
Cristian, you could use the second parameter:
$this->lang->load('about', 'fr');
Jérôme Jaglale
Nov 3, 2009
Great work. I am doing this small assignment and got familiar with CodeIgniter just for that. The aim of the assignment is i18n. I am using the form_validation library for my assignment and I need to have localized error messages for the library. If I create a lang file under application/languages/french/form_validation_lang.php how can I dynamically load it in the controller? Will your library do this? Thanks!
Dec 31, 2009
Yes, your helper sure helps!! Thanks again for the great work. :)
Dec 31, 2009
This is great !! Is this library working with HMVC library?
Jan 2, 2010
@alyvest: I think the better solution would be header("Location: " . $CFG->site_url($this->lang($this->languages[$this->default_lang()]).$URI->uri_string()), TRUE, 302); If no language is provided
Jan 9, 2010
hi this one is one of my favorites CI library i have one question is if i have default language is English and i dont want to use en in url and when i want to change language then i want lang name in url fr default localized
Jan 12, 2010
umefarooq, it's probably possible with a bit of customization: just one route for the fr (routes.php), no redirect if there's isn't any language in the URL and don't add the language segment if it's English (MY_Language.php).
Jérôme Jaglale
Jan 12, 2010
Hey Jérôme, thanks for the library, it's pretty wicked! Definitely saved me some time :) I am stuck with a little problem tho and was wondering if u can help me out. I'm trying to reroute some URIs to the same controller as such: /collection/2010 /collection/2009 etc should all reroute to the 'collection' class and pass the 'function' (2009 or 2010) as a variable. I've tried adding a simple route rule to the routes.php but haven't found a way to do so correctly... you got any ideas?!
Lennart Thiel
Jan 16, 2010
Hello, I tried to implement your script, but i get this error: Fatal error: Call to a member function localized() on a non-object in [app]\application\libraries\MY_Config.php on line 19 . Can you please explain what might be wrong? Thanks and great job ;)
Jan 17, 2010
Hi your library is no more working with modular separation here is the link so what's the solution for it.
Feb 3, 2010
Hi I have made some changes in your MY_Config.php file regarding special URI. I was working on it I have created admin panel which is my special URI but the form URI alway's getting lang segment in it. I have made some changes in site_url function may be will help all this library users
function site_url($uri = '')
  if (is_array($uri))
   $uri = implode('/', $uri);
  if (function_exists('get_instance'))  
   $CI =& get_instance();
                        $segment =  $CI->uri->segment(1);
   $uri = $CI->lang->localized($uri);   

  return parent::site_url($uri);
It will not localize form for special URI
Feb 3, 2010
here again modified site_url function
function site_url($uri = '')
  if (is_array($uri))
   $uri = implode('/', $uri);
  if (function_exists('get_instance'))  
   $CI =& get_instance();

                        $segment =  $CI->uri->segment(1);

                        if(!in_array($segment, $CI->lang->special))
   $uri = $CI->lang->localized($uri);

  return parent::site_url($uri);
Feb 4, 2010
Him Jerome!

I'm testing this on my local machine and I want to be able to change the language on my home page. I have this code:

&lt;?php echo anchor($this->lang->switch_uri('en'), 'EN'); ?&gt;
&lt;?php echo anchor($this->lang->switch_uri('ro'), 'RO'); ?&gt;

When I press any of the two links, the language remains the same... the default RO...

Can you help me with that?
Feb 10, 2010
Hi again!
I got this working by adding

$uri = $lang;

in the 'switch_uri' function.

Thanks again for this really useful!
Feb 10, 2010
* Thanks again for this really useful! :)
Feb 10, 2010
** Thanks again for this really useful feature!

I wonder what's with this hurry... :)
Feb 10, 2010
how can we get active language using this library.
Mar 1, 2010

you could use the uri class in your controller;
$data['curr_lang'] = $this->uri->segment(1);
Mar 19, 2010
thanks you
Mar 23, 2010
I have implemented this technic to my site. But when i check the header of my site's home page I see "HTTP/1.1 302 Moved Temporarily". But I wondwer if it will be problem for the google not to index regularly or pagerank problem?

Is there way to not to see this redirect for mysite?

My site : .

Thanks for the help.
Taner Ozdas
Apr 1, 2010
Sorry for the above message , I have commented below lines from MY_Language.php then the header become normal with 200 .

function MY_Language() {
//header("Location: " . $CFG->site_url($this->localized($this->default_uri)), TRUE, 302);
Apr 1, 2010
When i submit a form, I get the following error. I've also changed the file according to "webmasterdubai".


A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/MY_Config.php
Line Number: 21


A PHP Error was encountered
Severity: Warning
Message: in_array() []: Wrong datatype for second argument
Filename: libraries/MY_Config.php
Line Number: 21
Fatal error: Call to a member function localized() on a non-object in E:\wamp\www\mlc\application\libraries\MY_Config.php on line 22


What am i missing? I've also declared the special uri.

Thanks in advance
Nan V
Apr 1, 2010
Hi, Jérôme!

Is there a way to get this 'country_code' => 'language' array from a database table? I a model for this, but I can't call it within MY_Language library. Do you have any suggestions for this problem?
Thanks in advance!
Apr 4, 2010
I think a rewrite of redirect is needed,

localized wont work in my case coz I have to replace a lot.

how about adding a My_uri_helper that add language when redirect.

I'm having Problems with ION AUTH.
John Smith
Apr 5, 2010
Hey Jerome,
Is there a new version that I can download to use in my project.
Apr 5, 2010
To choose the default language based on the browser language, from Aleix Ventayol
function default_lang()
if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
$languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );

// $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3';
// need to remove spaces from strings to avoid error
$languages = str_replace( ' ', '', $languages );
// we change ; to , to create an array where language codes doesn't have quality
$languages = str_replace( ';', ',', $languages );
$languages = explode( ",", $languages );

//find which language we should use
//the array will have some entries like q=0.5, but we don't care about
//them cause we're not going to find them in the languages array, so we don't
//need to waste time removing them
foreach ($languages as $lang)
if (isset($this->languages[$lang]))
return $lang;

foreach ($this->languages as $lang => $language)
return $lang;
Jérôme Jaglale
Apr 15, 2010
Any help please...

When i submit a form, I get the following error. I've also changed the file according to "webmasterdubai".


A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: libraries/MY_Config.php
Line Number: 21


A PHP Error was encountered
Severity: Warning
Message: in_array() []: Wrong datatype for second argument
Filename: libraries/MY_Config.php
Line Number: 21
Fatal error: Call to a member function localized() on a non-object in E:\wamp\www\mlc\application\libraries\MY_Config.php on line 22


What am i missing? I've also declared the special uri.

Thanks in advance
Nan V
Apr 23, 2010
For use any Lang in route.php

// example:
$route['^../(.+)$'] = "$1"; // For 2 chars
$route['^...../(.+)$'] = "$1"; // For 5 chars ex.: /pt_br/about
$route['^..$'] = $route['default_controller'];
May 8, 2010
Hi, Jérôme,

Thanks a lot for this helpful library. We recently have forked it to add the support of hostname based language detection. The fork URL: May be it will help somebody 8)
Andrey Chernih
May 19, 2010
What is the best way to outputs translation from database?

I am planning to add a new table with id, language_id, reference_id (this will the id of original entry), reference_table(such as content, menu, etc), their reference_fields (it could be any fields from the original inputs), values, modified_date, modified_by and published.

I will appreciate any inputs. Thanks in advance.
i18n rocks
May 23, 2010
Hi all,

First at all sorry for my english,

I'm using the Modular Separation library by wirezdesign and philsturgeon but this extension doesn't seem to work. I tested extending MY_Language from MX_Language and MY_Config from MX_Config.

What can i do?

I like so much this library, and i would like to use it.
Jun 1, 2010
I solved my problem. I tried to extend MX_Config and MX_Language with MY_Config and MY_language and it worked.

Thank you anyway.

Jun 3, 2010
Thank you for your work on this plugin, it is much appreciated.
Jun 11, 2010
How could I use the array $lang in a controller ?, 'cuz when I put echo $this->lang->lang('example'); in the controller, la output is empty, and that should be "example", "Beispiel", "ejemplo", "exemplo" ...
Shaikiro Hoshamoto
Jun 16, 2010
Just wanted to say thanks for a great library! Good job mate!
Erik Brännström
Jun 17, 2010
Ohh, I know, sorry ...


That's. So I can use the array's key ($lang) in the controller.

Thanks for this great library ...
Shaikiro Hoshamoto
Jun 17, 2010
Constantin had fixed the problem with the function switch_uri(). I've modified this function to use a default language without letters, for example: -> Default language -> Spanish -> Portugues

function switch_uri($lang)
$CI =& get_instance();
$uri = $CI->uri->uri_string();

if ($uri != "")
$exploded = explode('/', $uri);

// If we have an URI with a lang --&gt; es/controller/method
if($exploded[0] == $this->lang())
$exploded[0] = $lang;

// If we have an URI without lang --&gt; /controller/method
// "Default language"
else if (strlen($exploded[0]) != 2)
$exploded[0] = $lang . "/" . $exploded[0];

$uri = implode('/',$exploded);

return $uri;

Shaikiro Hoshamoto
Jun 17, 2010
I added this to the MY_Language constructor (after the global variable decalarations):

$this->default_uri = $RTR->default_controller;
Jun 22, 2010
Mei, and what does it do ? I don't know whether it helps something ...
Shaikiro Hoshamoto
Jun 25, 2010
Thanks a lot, it worked perfectly. I'll try to use it with a database with English and spanish content, I'll let you know,
Juan Carlos
Jul 9, 2010

i just try to implement this cool feature to codeigniter 2.0.

unfortunately i can not get it work. any idea what i have to modify?

Jul 25, 2010
Hey there, great one.
I don't really understand why if no language is set in the URI MY_Language() would fallback to the default controller instead of calling the appropriate controller with the default language.

Could be useful in case your website was already online before i18n was added.

If anyone should need this, here's a quick hack to prevent default controller

(line 62 of MY_Language.php )

header("Location: " . $CFG->site_url($this->localized($this->default_uri)), TRUE, 302);


header("Location: " . $CFG->site_url($this->localized($URI->uri_string)), TRUE, 302);

This way if somebody went to this would basically redirect to

Hope makes sense...
Aug 11, 2010
Hi.. all.. can i get the language from the session not from uri segment.. thanks.. cause on the MY_Language class the get_instance() function is not found..
Aug 12, 2010
???????? ??????!???????!
Vladimir, Russia
Aug 29, 2010
Hello Jerome

Thank you very much for this very useful library!

I tried to extract form a database the languages for the array $languages from file MY_Language.php but it returns an error. Do you have any ideea?

Thank you!
Sep 15, 2010
Hi all,

at my site the first redirect to http//websites/website/en doesnt work. when add /en by hand everything works well. even the site_url() links. but at start when i add nothing, theres nothing happening...

can someone help me out?

regards, bart
Sep 17, 2010

may I know what is en and fr on the link above.. Is it a folder inside the language folder?

please help me. I'm just new to CI..

Thanks for this wonderful library..
Sep 20, 2010
now i get it..
im sorry for the noob question..


God bless!
Sep 21, 2010
Does anyone had a problem when gzip compression is active in codeigniter config? If I turn on the compression I can't switch to english version.. but in the default language (portuguese) all works fine. If i change the URL (mysite/pt/ to mysite/en/) browsers (FF, Chrome) return an error: Error 330 (net::ERR_CONTENT_DECODING_FAILED)... It may be related with the headers.. Did anyone had this problem before?
Pedro Gil
Sep 23, 2010
After some hours of debugging I realized that (for some unexplained reason) one of my English text files printed a strange symbol before <php start declaration. I just removed that symbol and all works as it should be!

Thanks anyway
Pedro Gil
Sep 23, 2010
Hello Jerome,
Thanks for a wonderful library. However I am struggling with getting this working with modular separation provided by Phil.
I need some guidance on the changes that need to be made. The above posts weren't that clear.

thanks in advance

Sep 28, 2010
hi Jérôme,

nice work,
is there any idea to make it work with codeigniter 2.0 ????
Oct 8, 2010
and we can do something like that in routers.php

$route['^(ar|de|en|es|fr)/(.+)$'] = "$2";
$route['^(ar|de|en|es|fr)$'] = $route['default_controller'];

instead of

$route['^ar/(.+)$'] = "$1";
$route['^de/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";
$route['^es/(.+)$'] = "$1";
$route['^fr/(.+)$'] = "$1";

$route['^ar$'] = $route['default_controller'];
$route['^de$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];
$route['^es$'] = $route['default_controller'];
$route['^fr$'] = $route['default_controller'];
Khaled Attia
Oct 20, 2010
I just test this in Codeigniter2+HMVC+Datamapper. To work you have to extends class from MX_ or MY_, copie the files to application/core and require the files on third_party. Then rename MY_Language to MY_Lang file and class. This only work if your controllers extends from MX_ or MY_. Tested with anchor and site functions and works like expected.
Miguel Ramos
Oct 28, 2010
Hello, I'm having trouble when I'm trying to make a custom route.
Here's an example:


When I acess
I get a 404 error.

Can anyone help me out?

Thanks. ^^
Camila Miguel
Nov 8, 2010
I am having the same issue as Camila here.. None of my custom routes are working.. any help would be great.
Nov 8, 2010
First use config like Khaled.

$route['^(ar|de|en|es|fr)/(.+)$'] = "$2";
$route['^(ar|de|en|es|fr)$'] = $route['default_controller'];

Second use :


You don´t need to use pt or other language!
Camila are you portuguese?
Miguel Ramos
Nov 10, 2010
To make it work with the latest CI 2.0 build use this:
class MY_Config extends CI_Config {

function site_url($uri = '')
if (is_array($uri))
$uri = implode('/', $uri);

// make it compatible with CI 2.0
if (class_exists('CI_Controller'))
$uri = get_instance()->lang->localized($uri);

return parent::site_url($uri);

Nov 18, 2010
I tried to add what Shaikiro Hoshamoto did, but I see no change hier are his codes again.. What could be a problem with my ci site? So I want to remove my deafult language in url like fr/create_account to be create_account
function switch_uri($lang)
$CI =& get_instance();
$uri = $CI->uri->uri_string();

if ($uri != "")
$exploded = explode('/', $uri);

// If we have an URI with a lang --&gt; es/controller/method
if($exploded[0] == $this->lang())
$exploded[0] = $lang;

// If we have an URI without lang --&gt; /controller/method
// "Default language"
else if (strlen($exploded[0]) != 2)
$exploded[0] = $lang . "/" . $exploded[0];

$uri = implode('/',$exploded);

return $uri;
Davor Radic
Nov 29, 2010
Can somebody tell me, how to get the following to work:

If the user enters an invalid or not supported language in the URI, I want the request being processed with the default language, e.g.: --&gt;
Dec 7, 2010

First, THANK YOU for this great library!
I'm quite new with framework and with MVC-model and I would like to implement the fuction described in #56 but I don't know where to add this function.
Can I have some explications about what to do ?

Dec 20, 2010
Hello, Miguel. Happy New Year! ^_^

I tried the way you showed, but I'm still having problems.
When I try to access
I get the following error:

A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Testimonials::index()
Filename: controllers/testimonials.php

And when I try, I get a 404 error page.

I really don't know what to do with it.
And, by the way, I'm Brazilian.

Thanks! ^^
Camila Miguel
Jan 3, 2011
How do I make this library to work with Codeigniter 2.0? It there a tutorial?
Edwin Mugendi
Jan 4, 2011
Here you go
Jan 8, 2011
Coooooooooool its working................!
Ashish Chuadhary
Jan 14, 2011
I had quit some trouble to get this one working on Codeigniter 2.0 in combination with HMVC extension. Also the modified version for 2.0 by Juris Malinens posted on has the same bugs.

In short:
- By using site_url() in the constructer in combination with the localized method in site_url() causes a invenent loop.
- In the 2.1 post there was a bug introduced that caused double language code in the url: The last line of the localized method should return '$uri' instead of "return $this->lang() . '/' . $uri;"
- the constructor should use parent::__construct(); instead of parent::CI_Lang();
- the used explode function in this class gives different result depending on if a uri will start with or without a forward slash.
- if the "special" uri array stays empty it causes the constructor not to redirect where it is supposed to.

I was not able to modify the code posted on the previous url. So instead I posed the classes as an attachment in the first comment post:

You should be able to download it from there. Instructions are incleded in case you want to use it in combination with the HMVC extension.
Jan 24, 2011
Interesting :) Your code doesn't work as well.

Jan 28, 2011
Not sure if you commented on my post. In case you had trouble with it. There was a bug in it that caused the "special" uri array not to work. This should be fixed with the latest upload.
Feb 1, 2011
Hello n0xie,
Then man, I'm trying to use Internationalization (i18n) library for CodeIgniter 2.0, but when I load my application, it gives the following error: unable to load the class Language. Went to check in CI 2.0, I do not have the language class. Dude, can you help me?
Fabricio Rodrigues
Feb 1, 2011
@Fabricio, the solution n0xie is suggesting doesn't not work. It just disables the whole function.
In this post on the forum where the i18n class for codeigniter 2.0 is discussed you will find the working files.

It would be nice if someone could upload them here also.

Good luck
Feb 3, 2011

Thank you for this this library. I 've integrate it with CI2 and hmvc. and it's working like a charm.

I only have 1 question.

Currently the structure i have is the following:

and i cannot find the route to have

would someone have an idea?

thank you
Feb 4, 2011
webwerken, Thanks Dude!!
Fabricio Rodrigues
Feb 7, 2011
This was a great tutorial ! I'm using an older version of CI, 1.7 and I'm happy with it.

Got a question:
I have a dynamic page, where the results come out of the database.
I want to split the results so that for each language only the related data is displayed.
It seems the query is not being passed to the lang-view page,

In my controller I have:

$data['query']=$this->db->query('SELECT * FROM albums ORDER BY releaseOrder DESC');
$this->template->load('template', 'disco',$data );

In my sys/lang/english/disco_view.php I have:

&lt;? foreach($query->result() as $row): ?&gt;
&lt;? endforeach?&gt;

But when I try to access $data I get this error:

Message: Undefined variable: query

This does work with one language....
Any ideas?

Thanks in advance

Mar 15, 2011
Dear Kamy,

I think you are trying to use one variable that it's not defined anywhere ($query). Maybe you have copy&paste; your code.

$query=$this->db->query('SELECT * ....');

Will define $query variable, while
$data['query']=$this->db->query('SELECT * ...);
not because the variable it's $data, not $query

Hope it helps

Mar 20, 2011
Hey Jérôme Jaglale,
Is there a new version that I can download to use in my project.
Apr 7, 2011
how can we pass multile array from language file to CI controller..
Mahendra Tyagi
Apr 16, 2011
Fatal error: Call to undefined method CI_Lang::switch_uri() ???
cuase i use index.php/ in my url how can i solve this problem ??!!
Apr 21, 2011
Thank you!
For CodeIgniter 2.x see, sources attached to the first post
May 5, 2011
Hello, Could you explain to me how to insert cookie ?

Jun 6, 2011
Does anyone know how to grab for example under loaded english language french language string?
Jun 10, 2011
sorry... but in my CI I don't find the folder:

i must to create the folder libraries?
Jun 16, 2011
how to do breadcrumb with ci?
Aug 8, 2011
how to do multi sub category by ajax?
sophal ngang
Aug 8, 2011
@henry: This reflects a change in CodeIgniter 2.x from 1.x. To make this library functional in 2.x, you will have to change the class names ("MY_Lang extends CI_Lang" in MY_Language.php and "MY_Config extends CI_Config" in MY_Config.php), that is, add "CI_" to the CodeIgniter class names and change the Lang class name, and change the name of MY_Language.php to MY_Lang.php. Then place these files in application/core/, instead of where this guy says to.
Dakota Schneider
Aug 20, 2011
hello, I have ci 2.0 and translations are working but my custom routes not.

/* custom routes */
// URI like '/en/about' -> use controller 'about'
$route['^(en|de)/(.+)$'] = "$2";
// '/en' and '/de' URIs -> use default controller
$route['^(en|de)$'] = $route['default_controller'];

$route['register'] = 'auth/register';
$route['login'] = 'auth/login';
$route['logout'] = 'auth/logout';

'register', 'login' and 'logout' are not routed to auth/something. Any idea why? I am getting 404 error (when I open en/login it wants to use login controller instead of auth)

what's wrong with this?
Aug 21, 2011
I found solution:
$route[’^(en|de)/register’] = ‘auth/register’;
$route[’^(en|de)/login’] = ‘auth/login’;
$route[’^(en|de)/logout’] = ‘auth/logout’;
$route[’^(en|de)/(.+)$’] = “$2”;
$route[’^(en|de)$’] = $route[‘default_controller’];

But I have one more trouble. When I try to login on en/login after form submition it redirects me at de/page instead of en/page. Why does it change language from en to de? thanks in advance
Aug 22, 2011
I am having trouble by indexing pages gogole.
How to make default controller without redirekto to lang

Sep 2, 2011
Thanks to webwerken! It works great. I've spent all night trying to figure why it's not working in CI 2.x. The solution was right in front of me :)
Sep 12, 2011
thanks,,, its work... in CI 1.7.2
but, i want to make route with URI 'about/en' or like '' , how can i change route configuration?

and how can i want not display uri segmen language in my other controller link, like =>
Nov 15, 2011
thanks for taking the time to explain how the Special URIs really really helped me

<a href="">Desarrollo Personal</a>
Desarrollo Personal
Jan 2, 2012
Hi, Just added a small function to the MY_Lang library that checks if a language code is supported in the website. it gets the language code and return TRUE/FALSE

function is_valid_lang($langCode)
if(array_key_exists($langCode, $this->languages))
return TRUE;
return FALSE;
Sagee Lupin
Jan 30, 2012
how to redirect the page to if I land to the page first time. My default controller is 'site' so now my uri looks like after landing:
normally without i18n in this situation url is (even 'site' is the def. controller)
any idea? thanks
Feb 26, 2012
I'm getting problems with this lib.
My forms are not sending post data.
Jérôme Jaglale, do you have any public e-mail? I need some resolution. My problems started when i added this library. :-)
Mauricio de Abreu Antunes
Mar 7, 2012
This March 29, 2012 update makes this library work with CodeIgniter 2.
Jérôme Jaglale
Mar 29, 2012
this is rally a gud framework!!!!!!!!!11
amit singh
Mar 31, 2012
I like this plugin - it does exactly what I need for my multilingual site. Except for one thing - the "Remove splash page" instructions don't work for me - if I remove ”” from the $special array I get a blank page every time.

I'm running the latest Codeigniter (2.1.0) - could this be the source of the problem. Anybody know any workarounds?

Mais, quoi, qu'il arrive, merci Jérôme pour un bout de code bien utile !
Tim Akeroyd
Apr 5, 2012
this good lib only work for me if i change the declaration of My_Lang default constructor:
from function MY_Lang()
to function __construct()

Is it right?
Apr 11, 2012
My problem just like Mauricio de Abreu Antunes, (post data not exist when swicth to another language).
Apr 19, 2012
I'm having the same problem as Tim Akeroyd. If I comment out the empty string, I get the following error:

"Fatal error: Class 'CI_Controller' not found"
Apr 28, 2012

I have one problem:

If I try to access an URI where the first segment is not a valid language prefix (in my case 'pt-br', 'en' or 'es'), it returns an error. For example:

Works fine

Return "Fatal error: Class 'CI_Controller' not found"

How could I resolve this error?


Felipe Ribeiro
Apr 30, 2012

I also encountered "Fatal error: Class 'CI_controller' .. " problem but I realised I've seen the error before.
After googling a little it got to me that get_instance() in MY_Config gets called before the Controller class is loaded. When I understood the problem I knew what to look for and here is the fix I found -

Hope it helps,
Matiss Bisofs
May 2, 2012
Now its working!!
Thanks a lot Matiss
Felipe Ribeiro
May 5, 2012
Great library. I'm using this for my new project. Thank you for putting it up for us.

Luis Milanese
May 7, 2012

Tu m'as l'air français alors, j'vais te remercier dans notre langue pour te dire un gros merci pour cette librairie.

Testé et approuvé. Par rapport à d'autres librairies d'internationalisation, tu utilises les fonctionnalités du core de CI, t'évites de ré-écrire la roue : c'est cool.

Ta doc est claire et nette. Pas une seconde de galère.


And if you are not French, I just say thank you for your good work.
May 9, 2012
This May 10, 2012 update fixes the "Fatal error: Class 'CI_Controller' not found" problem reported above and solved by n0xie.
Jérôme Jaglale
May 10, 2012
Hello, I found problem with special uri, form and csfr protection enabled. form helper doesnt generate csfr token, because its compare action uri with site_url(). site_url return localized uri, but form is on special not localized uri. this is solution:

// add language segment to $uri (if appropriate)
function localized($uri)
global $URI;

if($uri == '') $uri = $URI->uri_string();

|| $this->is_special($uri)
|| preg_match('/(.+)\.[a-zA-Z0-9]{2,4}$/', $uri))
// we don't need a language segment because:
// - there's already one or
// - it's a special uri (set in $special) or
// - that's a link to a file
$uri = $this->lang() . '/' . $uri;

return $uri;
Kristian Feldsam
May 17, 2012

if($uri == '' && $this->is_special($URI->uri_string())) return $uri;
Kristian Feldsam
May 17, 2012
Hi everybody,

I have seen that some people has been asking about the possibility to translate URI segments and not just change the first segment.
Since I needed it as well I created a hack around it and thought that I should share it.

Here is what you can do:

1. In MY_Lang.php, add these variable and function:

// Define segments that are to be translated

public $seg1 = array(
'en' => array('home', 'about'),
'fr' => array('acceuil', 'a-propos'),
'de' => array('heim', 'ueber-uns')

// translate() creates a dictionary with array_combine() and translates with strtr()

function translate($what,$from,$to)
$what = strtr($what,array_combine($this->seg1[$from],$this->seg1[$to]));
return $what;

2. Inside the switch_uri function, add:

$uri = $this->translate($uri,$this->lang(),$lang);

just before


Now you should be good to go. One more thing, when configuring your routing, everywhere you would have put 'about' or 'home', you can put:


This hack works perfectly on my website, if it doesn't work for you I must have made a typo mistake recopying it. Please give it a look and post it here for the others!

Joan Rodriguez
May 21, 2012
Very usefull and so simple as usual with CI.
May 24, 2012
Hi Guys,

I am building a website with an admin page. I am using this plugin to build the multilingual admin page. I am using HMVC also.

Is it possible to have the "http://localhost/mydomain/admin/login" a special page ( no language indicator in the url ) but when you are inside the admin page ( http://localhost/mydomain/en/admin/dashboard ) you will then have the language indicator in the url?

Jun 21, 2012
I have the problem like someone above has, when I land on my page, e.g. I type '' in my browser it shows:

, where 'home' is my default controller.

But, normally (without using i18n library) it would be without the default controller like:

Tahnks in advance for any advice
Jul 15, 2012

Comment faire pour que la langue par défaut soit à la racine / sans indication de langue, et garder une seconde langue avec accès classique par /en par exemple?

Merci de votre aide.
Aug 2, 2012
Hi ppl,

I am trying to convert a portuguese website in to english language using steps mentioned in .. I followed all the steps correctly but in the TEST step when go to the link http://localhost/en/about ... the output is correct but when I try to go to the link http://localhost/pt/about, the page gets redirected to http://localhost/en/home automatically and the display on the screen comes :

404 Page Not Found

The page you requested was not found.

Please help

Sep 27, 2012
Same problem as #143, please help
Oct 1, 2012

The redirect issue:

Regarding your previous comment related to dx_auth, I just wanna talk about a similar authentication code which is tank auth.

In order to make tank auth working with your i18n library, you have to:

1- remove the "" in MY_Lang:
// special URIs (not localized)
var $special = array (
2- strip out any '/' from the redirect/anchor ... functions in the tank auth controller and the view pages:
redirect('auth ...
Oct 1, 2012

I'm using Codeigniter_i18n, when get current language:
echo $this->lang->lang();

Output error:
Fatal error: Call to undefined method MX_Lang::lang() in .... echo $this->lang->lang();

Please to fix! Thanks
Steve Toan
Oct 1, 2012
if you are used modules HMVC the class MY_Lang must extends from MX_Lang, don't from CI_Lang
Oct 11, 2012
it got error at about.php with message "Fatal error: Call to undefined method CI_Lang::localized() in <b>C:\xampp\htdocs\codeigniter\application\core\MY_Config.php</b> on line <b>19</b><br />"
Oct 11, 2012

site_url() doesn't add language segment to the generated URL. Please help.

Oct 13, 2012
Good presentation,

Thank you
Oct 24, 2012
thanx. you da man!
Catalin Buletin
Oct 24, 2012
Hi !

Thanks for this, it works great.

I only wanted to share the fix I did to it to avoid a infinite redirect loop when you have a 404_overide like this:

$route['404_override'] = 'erreur/page_non_trouvee';

By default, if I don't do this, I get infinite loop if I type URL "/anything_with_no_language_in_front"

In MY_Lang Constructor:

Below "$segment = $URI->segment(1);" add:
$rsegment = $URI->rsegment(1);

Then use it in the if:

else if($this->is_special($rsegment) || $this->is_special($segment)) // special URI -> no redirect

Finally, add the controller in the $special array:

// special URIs (not localized)
var $special = array (

Tommy Lebel
Nov 1, 2012
how to make current_url() return the url after localization code?
in my case, when I call current_url() it returns me


what I want is


how to hack the current_url() function to make it works like I want?

Nov 27, 2012
When uri_string is empty we can't change language.
Any one solve this problem?
Dec 3, 2012
How I must to change routes for working that: =>{default_language or language i will set}/test/hello ?
Dec 4, 2012
I got this to work with one controller and one view but when I add a new controller and view the link takes me always to my first page.
I have a test_controller.php and a test_view.php.
I have added in the routes.php the following according to the instructions:
$route['default_controller'] = test_controller';
$route['^el/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";
$route['^el$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];
In My_Lang.php I have deleted the empty quotation marks in the Special arrays (not localized) section (no splash screen).
So far the site works OK and I can switch between two languages.
The address shows and it displays my test_controller.php etc content.
Then I tried to add a new controller and view: new_controller.php and new_view.php
But when I click on the link to take me to I am directed to
When I hover over the link I can see the link displayed at the bottom of the browser (Firefox) but I am taken to
I suppose I must add sth to the routes to make it work.
I tried $route[‘new_controller’] = ‘new_controller’; but didn’t work. The only way to load my new controller is to set it as default controller in the routes.php file instead of the test_controller.
I am missing something very basic I think but I can’t think of anything. Please, can anyone tell me how to add a new controller when this i18n is added?

Dec 18, 2012
Update: When I add manualy in the url
then my new page loads and everything works well from then on. I can change languages and go to the test_controller etc. But this en is not being added when I click the link.
Dec 18, 2012
Update2: Solved, I forgot to set the $default_uri. It should be $default_uri = 'test_controller'
It was sth stupid. Now everything works except that some elements of my page disappeared! When I set $default_uri='' the elements appear again!
Dec 18, 2012
I added in My_Lang.php

function load()...

* Disabled: Otherwise $this->lang->load('general', 'other_language_key'); doesn't work
if (in_array($langfile, $this->is_loaded, TRUE))
Dec 19, 2012
Everything's ok, but I'd like to take the languages list from database. That $language class variable would load languages from a sql table. But seems like I can't make any db query in MY_Lang constructor. I tried making another method and load it in a controller but it's not the same... Anyone has a good idea how to implement multi-language with db support?
Dec 31, 2012
How Can i create inner pages for that current language??
Jan 2, 2013
Hi there, for the example I have as the default site use en language, and I want at index of change to

thank you in advance
Feb 6, 2013
This website design style is very good!
Mar 27, 2013
Hi, I having problems with route.

$route['default_controller'] = "cc_main/showLogin";
$route['^(es|en)/(.+)$'] = "$1";
$route['^(es|en)$'] = $route['default_controller'];

$route['welcome'] = "cc_main/welcome";
$route['^(es|en)/(.+)$'] = "$2";
$route['^(es|en)$'] = $route['welcome'];

in my view I have:

<div><a href="&lt;?php echo site_url('welcome'); ?&gt;">Welcome</a></div>
when i do click on Welcome this does work, I am getting 404 Not Found. The requested URL /app_template/es/welcome was not found on this server.

I tried $route[’^(es|en)/welcome’] = ‘cc_main/welcome’; and not working.

how can i solve this problem?
Mar 30, 2013
I like and use your library, it works fine.
There is a little bug, within
function MY_Lang()
it doesn't return default language. When changed it returns the same value.
$new_url = $CFG->config['base_url'].'au'.$uri;
instead of
$new_url = $CFG->config['base_url'].$this->default_lang().$uri;

May 22, 2013
i am using this awesome library but i have a problem.
I want to add my sitemap like this in the routes

$route['sitemap\.xml'] = "sitemap"; // not working
$route['sitemap\.xml'] = "sitemap/index"; // not working
$route['^(de|gr|en)/sitemap\.xml'] = "sitemap"; //this working

but i do not want a language on this url.
I want the first one to get work.
Any ideas ?
Jul 22, 2013
In .htaccess, add a rule to redirect /sitemap.xml to /sitemap or /en/sitemap
Jerome Jaglale
Jul 22, 2013
Still doesn't work (here is my .htaccess with the new line commented)

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|favicon\.ico|robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ /index.php/$1 [L]
# RewriteRule ^.*sitemap\.xml$ /sitemap [L]
php_flag display_errors on
php_value error_reporting 7
Jul 22, 2013
Sorry, I couldn't get the .htaccess to work but this works:

In routes.php
$route['sitemap.xml'] = 'sitemap';
In MY_Lang.php, add it to $special:
// special URIs (not localized)
var $special = array (
(Basically the i18n library needs to know it's acceptable for this URI not to contain a language segment)
Jerome Jaglale
Jul 22, 2013
that works great :D thanks a lot
Jul 22, 2013
great work thnx...:)
Oct 9, 2013
Thank you very much! Nice tuto.
Oct 9, 2013
I have similar problem like in #85.

Here's an example:


When I access
I get a 404 error.

I put it in
Ing. Michal Hudak
Oct 15, 2013
Just for reference, translating an anchor works like this:
Oct 20, 2013
I have been using the i18n library, which works great for my project.

But since I need to write separate modules, I recently added CodeIgniter Modular Extensions ( ) and the navigation breaks.

How can I solve this issue please, I would love to use both the i18n library & Modular Extensions.

I think my application navigation fails to work because i18n library introduces adds a language segment in the site url, in my case my url is http://localhost/index.php/en/home and after adding Modular Extensions, my navigation/links stop working.

Thank you in advance.
Nov 26, 2013
hi please help urgent

I am worked on wamp server it is working fine.

I moved production that is linux ubuntu 404 page error comes.

Please help me asap.

Route :

$route['default_controller'] = "Main";
$route['404_override'] = '';
// example: '/en/about' -> use controller 'about'
$route['^te/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";

// '/en' and '/te' -> use default controller
$route['^te$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];
Dec 30, 2013
Great Work! Thank You for sharing.
Feb 14, 2014
This library has some security issue. Please check this.
Feb 26, 2014
how i can do this: -> Default language (en) -> Spanish

not show default language /en/ in the url
Juan Nina
Mar 6, 2014
Edit for auto check browser language
#Open MY_Lang.php
#Change default_lang() function this code
#Edit for your website languages

function default_lang()
$Auto_Check_Language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if($Auto_Check_Language = 'tr') {
return 'tr';
} elseif($Auto_Check_Language = 'en') {
return 'en';
} elseif($Auto_Check_Language = 'de') {
return 'de';
} elseif($Auto_Check_Language = 'ru') {
return 'ru';
Yusuf Ulusoy, Turkey(?stanbul)
Mar 18, 2014
I saw you can internationalize CodeIgniter with with this library
Apr 9, 2014
Hi please help urgent !

how i can do this: -> Default language (en) -> Spanish

not show default language /en/ in the url

Thank you
Apr 11, 2014
You need targeted traffic to your website so why not try some for free? There is a VERY POWERFUL and POPULAR company out there who now lets you try their website traffic service for 7 days free of charge. I am so glad they opened their traffic system back up to the public! Check it out here:
Apr 21, 2014
We have decided to open our POWERFUL and PRIVATE website traffic system to the public for just a few days! You can sign up for our UP SCALE network with a free trial as we get started with the public's orders. Imagine how your bank account will look when your website gets the traffic it needs. Visit us today:
Apr 23, 2014