CodeIgniter Forums
Set default language from session internationalization i18n - 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: Set default language from session internationalization i18n (/showthread.php?tid=48135)



Set default language from session internationalization i18n - El Forum - 01-05-2012

[eluser]kolxoznik1[/eluser]
I am using CodeIgniter 2.1 internationalization i18n and I do not want to do the default language fr website but want to give people chance to choose their.

So for now I am using

MyLang.php

Code:
function default_lang()
     {
        $browser_lang = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? strtok(strip_tags($_SERVER['HTTP_ACCEPT_LANGUAGE']), ',') : '';
        $browser_lang = substr($browser_lang, 0,2);
        
        return (array_key_exists($browser_lang, $this->languages)) ? $browser_lang: $this->default_language;
     }

But I want to set default language from session! is it possible ? I tried this code but it get error

Code:
if ($this->session->userdata('language') != '')
            {
            $lang = $this->session->userdata('language')
            }

but it get error

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: MY_Lang::$session

Filename: core/MY_Lang.php

Line Number: 184



Set default language from session internationalization i18n - El Forum - 02-13-2012

[eluser]Reevak[/eluser]
I have the same issue! I want to use sessions to determine the language if a session exists! Was anyone able to solve this??


Set default language from session internationalization i18n - El Forum - 02-14-2012

[eluser]Unknown[/eluser]
Because the file is auto required from /components, whereas it isn't in /controllers


Set default language from session internationalization i18n - El Forum - 02-26-2012

[eluser]Noobigniter[/eluser]
any solution ?


Set default language from session internationalization i18n - El Forum - 02-27-2012

[eluser]Reevak[/eluser]
I found a good answer here Smile Just use a cookie that will be set previously by the user somewhere else in the page. That cookie's value will be a language (such as en, es...) and the code posted in this page works!!

http://stackoverflow.com/questions/9282949/codeigniter-2-1-internationalization-i18n-override-default-language-if-user-da