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

[eluser]nbaumann[/eluser]
Hey,

I just started using CI for a multilingual site and I'm having issues with language switching.

I basically have three links to a function which sets a language the following way:

Code:
$this->config->set_item('language', 'english');

However, this doesn't change the language at all. The config seems to change because the correct language is output when I do this:

Code:
echo $this->config->item('language');

But when I try to echo a line from a language file, it always fetches the English one even though when I echo the language config it's telling me it's another language.

Am I going about this the right way? I've been doing what I read in the documentation and it doesn't seem to work. Any ideas?

Thanks!
#2

[eluser]WanWizard[/eluser]
Are you language files loaded before or after you change the language? Does the other language exist as a folder in the languages directory? And does your webserver has sufficient rights to the files?
#3

[eluser]nbaumann[/eluser]
I've tried a lot of things. I tried this:

Code:
$this->lang->load('custom', $this->session->userdata('user_lang'));

I also tried this:

Code:
$this->config->set_item('language', $this->session->userdata('user_lang'));
$this->lang->load('custom', $this->session->userdata('user_lang'));

None of it works, it just always defaults to English and I know that the session is working because when I echo it, it displays the correct language, same thing when I echo the config. It just doesn't want to switch.

I'm running this on my local machine.

Thanks
#4

[eluser]Unknown[/eluser]
[quote author="nbaumann" date="1278252311"]Hey,

I just started using CI for a multilingual site and I'm having issues with language switching.

I basically have three links to a function which sets a language the following way:

Code:
$this->config->set_item('language', 'english');

However, this doesn't change the language at all. The config seems to change because the correct language is output when I do this:

Code:
echo $this->config->item('language');

But when I try to echo a line from a language file, it always fetches the English one even though when I echo the language config it's telling me it's another language.

Am I going about this the right way? I've been doing what I read in the documentation and it doesn't seem to work. Any ideas?

Thanks![/quote]
According to me many people have same type of problem as you have....
#5

[eluser]nbaumann[/eluser]
Is there really no one else with this issue? Or what am I doing wrong? I've been googling Internationalization with CodeIgniter, there's barely anything about it and it looks like I'm not going to be able to use CI's core for this.
#6

[eluser]WanWizard[/eluser]
Set the maximum log threshold (which will write debug messages about language files loaded), and add a log message to your code after you switched languages.
Then check your logs to see what is loaded when.

This is the way it should work, and it does here.

p.s. These posts leave me a bit confused. You code
Code:
$this->config->set_item('language', 'english');
and then you are supprised that the english languages files are loaded?
#7

[eluser]nbaumann[/eluser]
Nah, that was just an example, I'm actually passing a session in the second attribute. I'm going to try to see if what you told me gets me any further.

Edit:
Looking at the logs, seems like the english file is always loaded:

Language file loaded: language/english/custom_lang.php

Even though this what I'm doing:
Code:
$this->lang->load('custom', $this->session->userdata('user_lang');

And when I echo the user_lang session, it displays the correct language that I'm selecting each time. It seems like no matter what I pass to be loaded, it always loads it in the default language.
#8

[eluser]cahva[/eluser]
The only explanation for this is that you have autoloaded custom language file. You cant change the language on-the-fly. So if you loaded the english version of custom, you cant load it again with other language(unless you want to extend the language class.).
#9

[eluser]nbaumann[/eluser]
I found Language Selection 2 and it seems to work.

I'm a little disappointed that the language cannot be changed the way I was trying using CI's core, it makes logical sense for me to do it that way.
#10

[eluser]cahva[/eluser]
Well atleast in normal situations you really dont need to load multiple languages per page Smile




Theme © iAndrew 2016 - Forum software by © MyBB