I have a function for language (like the system that WordPress and other CMSes have) to retun a term in defined language as
function lang($term) {
include "language/cn.php";
if(!empty($tans[$term])) {$translatedterm=$tans[$term];}
else { $translated = $term;}
return $translated;
}
The problem is that I want to offer the option of choosing language on menu, as people can change the language. To this aim, I need to update the value of “include ‘language/cn.php'” for every language. It should be include "language/$language.php"; but $language is a string coming from menu selection and is outside the function. Do you have any idea how to change the language file inside the function depending on the language selected?
According to the hint given by Alex Howansky, the ultimate solution is to use a php variable like $_SEESION, $_GET, $_POST, etc. These variable can be used within a function. However, as a function has its own scope, a static string from outside a function cannot be read inside the function.