1

I already read and follow the instruction from this link codeigniter_i18 multilanguage and it's works, but I have a little problem here, I don't know maybe at the routes config or the scripts.

for the example, this http://mysite.com is en default language in index of the site, but if I want to change different language for the instance dutch, so how to implement that I can get the url like this http://mysite.com/nl/

thanks in advance

2
  • hi you want to make nl as default language or you want to go on nl language from english language if so then use this from same library anchor($this->lang->switch_uri('nl'),'Display current page in French'); Commented Feb 7, 2013 at 5:23
  • @umefarooq hi, I know about that, but not that one I asked, sorry. Commented Feb 7, 2013 at 6:35

1 Answer 1

1

Using it in the path like actually makes things a lot more complicated, because you ALWAYS need the first segment to be a country code (so you need to use /en for English)

An easier method to consider is to set a session variable when they select a language, and do it "in the background":

In your MY_Controller:

public function __construct()
{               
parent::__construct();
$lang_code = ($this->session->userdata('lang_code'))? $this->session->userdata('lang_code'):'english';
$this->lang->load('project_launch', $lang_code);
$this->lang->load('project_launch_template', $lang_code);
$this->lang->load('project_launch_uploader', $lang_code);
}

function lang_select(){
    $lang_code = $this->input->post('lang_code');
    $this->session->set_userdata('lang_code', $lang_code );
}

and have your language selector (dropdown, little flags, whatever) call lang_select() to change the language & set the session variable; the construct will check the language each page load and load the appropriate language files

Sign up to request clarification or add additional context in comments.

2 Comments

hi thank you for your quick response. So every time I change the language I have to set the session?
yes, exactly. but most people won't change language much - it isn't really a drain. Pages will check if the session is set & not re-set them. So not much impact on server

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.