Welcome Guest, Not a member yet? Register   Sign In
Always get english page using i18n
#1

[eluser]reaper_unique[/eluser]
I have a multi-language site that uses i18n.

I set a cookie to remember what language the user has selected. The cookie gets set and you can switch between the languages when you click the link that makes you switch between languages and the cookie will change as well.

The problem however, is when you leave the page. When you come back the cookie still has the value of the language you left the page on (e.g. Dutch) but no matter what, the site will always load with English even though that is:
1. Not the language of the cookie;
2. Not the default language in the config or my_Lang file;

I check the cookie on every page like this:
Code:
$cookie_language = '';
  $selected_language = $this->uri->segment(1);
  
  if (isset($_COOKIE['language_selection'])) {
   $cookie_language = $_COOKIE['language_selection'];
  }
  else {
      setcookie('language_selection', 'nl', time()+(86400 * 30), "/");    
  }

  if (empty($selected_language) && empty($cookie_language)) $this->lang->load('home', 'dutch');
  if ($cookie_language === 'nl') {
   $this->lang->load('home', 'dutch');
  }
  if ($cookie_language === 'en')  $this->lang->load('home', 'english');
  
  if ($selected_language === "nl")setcookie('language_selection', 'nl', time()+(86400 * 30), "/");
  if($selected_language === "en") setcookie('language_selection', 'en', time()+(86400 * 30), "/");

Anyone know why it always loads in english?

P.S.: how can I efficiently load the above code everytime? As a library? helper? Controller? What?

Edit: Oh yea, I'm also using a small library for a main layout.




Theme © iAndrew 2016 - Forum software by © MyBB