Page 1 of 1
function();
Posted: Tue May 18, 2004 2:58 pm
by ol4pr0
Kinda stupid maby but , i cant find my error
Code: Select all
function lang_set($option) {
if ($_GET['lang'] == 'en') {
include("inc/lang_en.inc");
}
if ($_GET['lang'] == 'es') {
include("inc/lang_es.inc");
}
}
// and some more..
$lang_set = lang_set($option);
//this wont include a language file.
echo $_GET['lang']; // returns the language (en / es / fr / .. )
Posted: Tue May 18, 2004 3:11 pm
by dull1554
try just lang_set($option); rather then setting it to a $var that might solve your problem...
Posted: Tue May 18, 2004 3:15 pm
by litebearer
Code: Select all
function lang_set($option) {
if ($option == 'en') { include("inc/lang_en.inc"); }
if ($option == 'es') { include("inc/lang_es.inc"); }
return "yes"
}
lang_set($_GETї'lang']);
I think that should do the trick
Posted: Tue May 18, 2004 3:33 pm
by ol4pr0
I am afraid that did not work. Thanks for trying
Outside the function it works fine..
However for later abuse, i would like to have been able to run inside a function();
Posted: Tue May 18, 2004 3:49 pm
by PrObLeM
i dont see where you set $option...
Posted: Tue May 18, 2004 4:15 pm
by dull1554
it really dont matter, he does not use $option in the lfunction
would you have to set $_GET as a global?
i.e.
Posted: Tue May 18, 2004 4:33 pm
by ol4pr0
let me try that .. $_GET global thing there.. i might indeed forgotten that
Hmm, couldnt get this to work.
tried differant things.
Code: Select all
$lang = $_GET['lang'];
function lang_set($option);
global $lang;
if ($lang == 'en') {
include (this)
}
}
and all other options posted above.. including the one that does make use of the $option
Posted: Tue May 18, 2004 4:35 pm
by markl999
$_GET is a 'superglobal', meaning it's always in scope. So no need for global $_GET
Posted: Tue May 18, 2004 4:47 pm
by ol4pr0
That means something else must go wrong when putting that in a function .
Posted: Tue May 18, 2004 4:51 pm
by ol4pr0
The function itself works when changing the include to a echo line
Code: Select all
if ($_GET['lang'] == 'en) {
echo "English included";
}
So is there something that wont allow me to include within a function ?
Posted: Tue May 18, 2004 5:00 pm
by ol4pr0
As it seems i had to include the file that holds the language $vars aswell within the function not really the ideal solution tho.. since i can now only execute the function there where i need it..
This has mainly to do with a dhtml menu bar that i am using. so when exucuting that language settings the menu bar will apear on that spot aswell.
instead on the spot / place where it should be.
it works.. but there should be something else

Posted: Tue May 18, 2004 5:44 pm
by feyd
why not..
Code: Select all
$lang = (isset($_GET['lang'])?$_GET['lang']:"en");
if(is_readable($file = "lang/lang_$lang.inc"))
include($file);
else
die("unknown language");
unset($lang);