I am making my site multilingual and the solution that I went with is to leverage CI's language system(that is, I am using language files).

I am using this addon to access language variables from the language files. Here is the code used to retrieve the language strings

$lang_file = ($this->EE->TMPL->fetch_param('file')) ? $this->EE->TMPL->fetch_param('file') : 'custom_label';


$param = $this->EE->TMPL->fetch_param('value');

$string = ($this->EE->lang->line($param)) ? $this->EE->lang->line($param) : '';

return $string;

I noticed though that no languages was set here. So I assumed that it is being set somewhere before this code executes.

I tried changing the languages in the Localization Settings for each member and the addon worked, getting only the strings from that language.

That is all well and good but it does have a problem in particular.

The current system only works for members. What if a guest(logged out user) wants to change language?

Solutions I am currently thinking are

  1. Instead of relying on the saved preferred languaged, I would base it on the url segment

    http://domain.com/en/test and http://domain.com/fr/test

  2. Store the language code in session

However, both of this can only work if I can override the currently set language.

Is there a way to do this?

P.S. Please don't suggest using addons like Publisher or Transcribe. I want to do this without using those addons.

1 Answer 1


You need to set the language code each time when a page loads. I think, you would know that a language can be set with config variable (within config.php) like: $config['language'] = 'english';. You should have the same logic and use the hook sessions_start. Within the hooked extension you can set the language like $this->EE->config->_global_vars['language'] = 'french';

Also, I think it would be good to set language in cookie so Global Var's language value can be assigned from cookie to avoid getting the language again and again from URI (with language code like http://domain.com/fr/test).

I used this method about 6 months ago so not sure about the exact code to share with you. Although, I hope it would help you.

  • Hmmm...so basically, base the language on a cookie. Ok, will try. Commented Aug 27, 2013 at 6:53
  • I am suggesting to set the language in cookie if you are redirecting users/guests to specific language site based after checking country or IP because you will not need to check the language again and again. The language variable can be assigned directly with cookie value if cookie is already set. In case, you are having other approach, you can skip the setting the cookie value and just assign language global variable. Commented Aug 27, 2013 at 8:41
  • i.e you will need to set only $this->EE->config->_global_vars['language'] = 'french'; for your need. Commented Aug 27, 2013 at 10:04
  • My goal was to just allow users(even those who are not members) to switch to whatever language they want. Remembering languages is great but it is never really required. So this solution might work. Commented Aug 27, 2013 at 11:07
  • The problem is where to submit the language switcher form so that it can be processed and set as cookie if needed or just set as global vars. Commented Aug 27, 2013 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.