Welcome Guest, Not a member yet? Register   Sign In
Problem Loading Language Files
#1

[eluser]AgentPhoenix[/eluser]
I've got an application I'm starting to work on and one of the features I want to include is the ability for users to set the language they see the system in. I'm gonna be storing their language preference in the session and calling it from there, but when I try to call the language file then print out a text line from the language files, I get nothing. I tried to assign the return of the lang->line method to a variable, but trying to echo that variable out produces an error to the effect of variable not defined. Any ideas?

In my controller:
Code:
$language = 'spanish';
$this->lang->load('sol_lang', $language);

Language file:
Code:
$lang['gen_one'] = 'Spanish';

In my view:
Code:
<p>&lt;?=$this->lang->line('gen_one');?&gt;</p>
#2

[eluser]Pascal Kriete[/eluser]
I'm stumped, can't see anything wrong.

Try this:
Code:
$tmp = $this->lang->load('sol_lang', 'spanish', TRUE);

echo '<pre>';print_r($tmp);echo '</pre>';

If that comes up empty then double check your paths and file names.
#3

[eluser]AgentPhoenix[/eluser]
Thanks for the quick reply, inparo! I gave the code you showed a shot and nothing comes back. I double checked paths and filenames too and everything seems to be in order.

Code:
application
   language
     english
       sol_lang.php
     spanish
       sol_lang.php
#4

[eluser]Pascal Kriete[/eluser]
Odd. we might be missing something very basic here. I see no errors though, so it's debug time.

Go to system/libraries/language.php and in the load function place echo statements in front of the various returns and try to figure out where it exits, that should help us identify the problem.
#5

[eluser]AgentPhoenix[/eluser]
Hmm, odd.

Before I posted this thread, when I would try to spit out the language stuff, nothing happened. It just didn't display anything, but I wasn't getting any errors. Now, I'm getting an error about not being able to include the file after putting in some debug code in the Language class. Apparently when you load a language file you can't include the _lang part. So I corrected the _lang part and it was spitting everything out fine with the debug code. Pulled the debug code out and it still works, so I'm not sure what happened originally. Thanks inparo for the quick and helpful responses!

One of the EllisLab folks, do you think something could be added to the user guide that mentions explicitly that you don't need the _lang part when loading language files manually? Thanks!
#6

[eluser]Pascal Kriete[/eluser]
Glad I could help.

My language library has this line in it:
Code:
$langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT;

Which should remove the _lang if it's there, thus allowing you to load it with or without.




Theme © iAndrew 2016 - Forum software by © MyBB