\n"; foreach ($languageArray as $key => $value) { // $key loops over "en", "fr", "nl", ... // $value will be an array like $value["name"] = "English" and $value["file"] = "en.inc.php" if ($key == $currentlanguage) { $selected = "selected=\"selected\""; } else { $selected = ""; } echo "\n"; } // end while echo "\n"; } // End function printLanguageSelect // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function includeLanguageFile() { // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_messages; $languageArray = getLanguageArray(); // If language exists, include the language file if (array_key_exists($net2ftp_globals["language"], $languageArray) == true) { $languageFile = glueDirectories($net2ftp_globals["application_languagesdir"], $languageArray[$net2ftp_globals["language"]]["file"]); require_once($languageFile); } // If it does not exist, use the default language nr "en" (English) else { $net2ftp_globals["language"] = "en"; $languageFile = glueDirectories($net2ftp_globals["application_languagesdir"], $languageArray[$net2ftp_globals["language"]]["file"]); require_once($languageFile); } } // end function includeLanguageFile // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ************************************************************************************** // ** ** // ** ** function __() { // -------------- // This function returns a translated message; the core standard function used is sprintf (see manual) // Input: - from function argument: message name $args[0] and variable parts in the message $args[1], $args[2],... // (there is a variable nr of variable parts) // - from globals: the array of messages $message // Output: string in the language indicated in $net2ftp_language // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_globals, $net2ftp_messages; // ------------------------------------------------------------------------- // Get the arguments of this function // $args[0] contains the messagename // $args[1], $args[2], ... contain the variables in the message // ------------------------------------------------------------------------- $numargs = func_num_args(); $args = func_get_args(); $messagename = $args[0]; // ------------------------------------------------------------------------- // Create the argument for the sprintf function // Aim is to have something like: sprintf($string_with_percents, $args[1], $args[2], ...); // As there is a variable nr of arguments in the function __, there is also a variable // nr of arguments in sprintf, and this must be constructed with a loop // ------------------------------------------------------------------------- // Check if the message with that $messagename exists if (@array_key_exists($messagename, $net2ftp_messages)) { $string_with_percents = $net2ftp_messages[$messagename]; } else { return "MESSAGE NOT FOUND $messagename"; } $sprintf_argument = "\$translated_string = sprintf(\$string_with_percents"; for ($i=1; $i<$numargs; $i++) { $sprintf_argument .= ", @htmlentities(\$args[$i], ENT_QUOTES)"; } // end for $sprintf_argument .= ");"; // ------------------------------------------------------------------------- // Run the sprintf function // ------------------------------------------------------------------------- eval($sprintf_argument); return $translated_string; } // end function __ // ** ** // ** ** // ************************************************************************************** // ************************************************************************************** ?>