Welcome Guest, Not a member yet? Register   Sign In
Language Switching Problems
#11

[eluser]nbaumann[/eluser]
I'm not trying to load multiple languages per page. I was trying to change the default language when a user clicks on a language, but that just didn't work.
#12

[eluser]WanWizard[/eluser]
It does work, it just doesn't work the way you have implemented it.

As I wrote before, you have to set the language before loading the language files.

CI uses this code to detect if a language file is already loaded. If so, it stops futher processing.
Code:
$langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT;

if (in_array($langfile, $this->is_loaded, TRUE))
{
    return;
}

As you see, the language itself is no part of this, which means that a switch of language is not detected.

There are two possible workarounds:
1) extend the language library, and modify the behaviour of the load() method so it does use the selected language
2) extend the language library, and add a switch_language method, that sets the new language, the reloads all already loaded languages files

If you would have used the search option of this forum (hint, search for 'switch language'), you would have found an answer to this question, including example code to work around this problem.
#13

[eluser]mk3[/eluser]
Try to do language switching in MY_Controller, actually it worked for me when I needed show error messages either in English or French.
#14

[eluser]WanWizard[/eluser]
That works if you know the language up front (either through config, session or database), not if you need to switch half way.

I my case, I can have the site default in german, a user that prefers french, and template elements that have to be in spanish. That means a lot of switching going on...
#15

[eluser]Sixer[/eluser]
I'm having the same problem I think.

I have MY_Controller that loads english by default.

But when a user selects a different language in their account settings, I want that new language to be loaded rightaway when they click Save Changes, so that when the settings page is loaded after form submit, it's in the newly chosen language.

So, in my Account Settings controller, I do a new $this->lang->load() with the language selected in $_POST. This line however has no effect. The user won't see the new language until he reloads the newly loaded settings page.

Is there any way to unload the current language and load the new language before going to view?
#16

[eluser]Sixer[/eluser]
The solution is here:

http://ellislab.com/forums/viewreply/339962/

Involves extending CI_Language with a short MY_Language class.




Theme © iAndrew 2016 - Forum software by © MyBB