CodeIgniter Forums
Language switch with sessions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Language switch with sessions (/showthread.php?tid=55615)

Pages: 1 2 3


Language switch with sessions - El Forum - 11-05-2012

[eluser]siptik[/eluser]
[quote author="Ewout" date="1352109043"]Maybe the first click doesn't seem to effect the page because the language load happens before the initialization in the index function.[/quote]
It's work fine on my computer!!!
I tested his project and my colleague tested it, but it works fine for us!


Language switch with sessions - El Forum - 11-05-2012

[eluser]chris1986m[/eluser]
Yeah siptik,

its soo strange!!

I test it again on two other systems and it doesn't work...

@Ewout: I think so too. But how can I fix the problem with this timing? Saving session in database is not possible at the moment.





Language switch with sessions - El Forum - 11-05-2012

[eluser]Ewout[/eluser]
What if you haven't selected a language at the start? Is it german then?


Language switch with sessions - El Forum - 11-05-2012

[eluser]siptik[/eluser]
Try update the framework.


Language switch with sessions - El Forum - 11-05-2012

[eluser]chris1986m[/eluser]
Yes on start its german. Look at the code on the top.
defaultLanguage = german "de"

Code:
if (!$this->session->userdata('language'))
    $this->session->set_userdata('language','de');

Updating is good idea. I'll test it.


Language switch with sessions - El Forum - 11-05-2012

[eluser]LuckyFella73[/eluser]
Hi Chris,

I would recommend you to use Maestrics library. It does
what you started to solve yourself providing everything
you need so far. Only difference I can see is that in his
library the language identifier is set in the first
url segment.

http://maestric.com/doc/php/codeigniter_i18n


Language switch with sessions - El Forum - 11-05-2012

[eluser]chris1986m[/eluser]
Cool!
I'll test it this week and i hope its the reason for my problem.


Language switch with sessions - El Forum - 11-19-2012

[eluser]chris1986m[/eluser]
Hi at all,

sorry for my late response.

Now i have solved my problem.
Here is the controller which works very nice.

Code:
class Start extends CI_Controller {
public function index() {
        $language = $this->session->userdata('language');
        $this->lang->load('main', $language);

  //Check language
  if ($language == '')
   $this->session->set_userdata('language', 'de');

public function languageSwitch() {
  $this->session->set_userdata('language',$this->uri->segment(3));
  $this->lang->load('main', $this->session->userdata('language'));
  redirect('/');
}
}

Thanks for all your help.


Language switch with sessions - El Forum - 11-24-2012

[eluser]chris1986m[/eluser]
Hi at all,

this week i get a message, that the language switch problem is always there...
I become crazy...

So this morning i checked all my code again and split it.
Please, is there someone who can help?

Code:
$autoload['libraries'] = array('session', 'user_agent');
$autoload['helper'] = array('url', 'language');
$config['language'] = 'de';

start.php controller
Code:
class Start extends CI_Controller {
public function index() {
        $language = $this->session->userdata('language');
        $this->lang->load('main', $language);

  //Check language
  if ($language == '')
   $this->session->set_userdata('language', 'de');

        //Check mobile version
        if ($this->agent->mobile())
            $this->load->view('mobile');
        else
            $this->load->view('index');        
}
}

language.php controller
Code:
class Language extends CI_Controller {
public function set($language) {
  $this->session->set_userdata('language', $language);

  redirect('http://uuu.uu.uu/');
}
}

href="/language/set/en"
href="/language/set/de"

Please let me know if you have some ideas.
Thanks!


Language switch with sessions - El Forum - 11-24-2012

[eluser]chris1986m[/eluser]
Hey,

i think the problem are the sessions.
After the reload the session variable will be overwritten?
The controller language works fine. But something is shit in the start controller.

When i remove the redirect code and will manual reload the page after language switch. Everything works fine!

PHP is not my favorite... As an Frontend-Developer, i work with Javascript...

:down:

Greets