'); fclose($fh); $real_interface_size = sizeof($interface); //Now run trough each language and recompile their //lookup arrays. if (is_dir($langdir.$transdir)) { if ($dh = opendir($langdir.$transdir)) { //If dir exists while (($file = readdir($dh)) !== false) { //read contents if ($file==".." or $file=="."){ } else if (substr($file,-3)==".po"){ //only files ending in .po /////////////////////////////////////////////////////////////////////////////////////////////////// language_log("----------------Compiling $file---------------",0); $language = parseLanguage($langdir.$transdir.$file, $interface); if (!$fh = fopen($langdir.$compdir.$file.".inc","w")) { language_log("ERROR: could not access $langdir $compdir - please check permissions",2); exit;}; fwrite($fh, "'); fclose($fh); ////////////////////////////////////////////////////////////////////////////////////////////////// } else { //debug("File $file with unknown extension found in $info_dir"); } } closedir($dh); } else { //debug("$info_dir could not be opened - check permissions?"); } } else { //debug("$info_dir not found or is not a directory"); } //Do the same again, this time for the project specific language files and instead of //creating new compiled files just add to whatever existing ones if (is_dir($langdir.$prjtransdir)) { $interface = parseLanguageInterface($langdir.$prjtransdir.$lang_project_default.".po"); //Get the interface if (!$fh = fopen($langdir.$compdir."language_interface.inc","a")) { language_log("ERROR: could not access $langdir $compdir - please check permissions",2); exit;}; fwrite($fh, "'); fclose($fh); if ($dh = opendir($langdir.$prjtransdir)) { //If dir exists while (($file = readdir($dh)) !== false) { //read contents if ($file==".." or $file=="."){ } else if (substr($file,-3)==".po"){ //only files ending in .po /////////////////////////////////////////////////////////////////////////////////////////////////// language_log("----------------Compiling project specific $file---------------",0); $language = parseLanguage($langdir.$prjtransdir.$file, $interface); if (!$fh = fopen($langdir.$compdir.$file.".inc","a")) { language_log("ERROR: could not access $langdir $compdir - please check permissions",2); exit;}; fwrite($fh, "'); fclose($fh); ////////////////////////////////////////////////////////////////////////////////////////////////// } else { //debug("File $file with unknown extension found in $info_dir"); } } closedir($dh); } else { //debug("$info_dir could not be opened - check permissions?"); } } else { //debug("$info_dir not found or is not a directory"); } } /*************************** * Have some of the files changed? **************************/ function languagesNeedsRebuild($langdir,$transdir,$prjtransdir, $compdir){ // return true; //Uncomment this to speed up things when you know that you will manually recompile the languages when updated... $last_compile = filemtime($langdir."last_compile_timer"); //This file gets touched each time a compile finishes if (is_dir($langdir.$transdir)) { if ($dh = opendir($langdir.$transdir)) { //If dir exists while (($file = readdir($dh)) !== false) { //read contents if ($file==".." or $file=="."){ } else if (substr($file,-3)==".po"){ //only files ending in .po if (filemtime($langdir.$transdir.$file)>$last_compile) return true; } } closedir($dh); } } if (is_dir($langdir.$prjtransdir)) { if ($dh = opendir($langdir.$prjtransdir)) { //If dir exists while (($file = readdir($dh)) !== false) { //read contents if ($file==".." or $file=="."){ } else if (substr($file,-3)==".po"){ //only files ending in .po if (filemtime($langdir.$prjtransdir.$file)>$last_compile) return true; } } closedir($dh); } } return false; //All checks say that nothing has changed. } /************************** * Parses a gettext .po-file into an indexed PHP array, * checking for inconsistencies if needed. * The $file is parsed and validated against $interface *************************/ function parseLanguage($file, $interface){ if (sizeof($interface)<1){ language_log("No interface defined for 'compileLanguages()'",2); exit;} $translation_file = file($file); $first_entry = true; for ($i = 0;$i=$lang_log_level){ $fh = fopen($lang_log_file,"a"); fwrite($fh, date("Y-m-d H:i:s",time())." ".$msg." ".$message."\n"); fclose($fh); } } if (languagesNeedsRebuild($lang_language_dir, $lang_translations_dir, $lang_prj_translations_dir, $lang_compiled_dir) || get_str("compile_languages")){ buildLanguages($lang_language_dir,$lang_translations_dir,$lang_prj_translations_dir, $lang_compiled_dir); } // Define some constants that the language files can use in the translation: $PROJECT = PROJECT; if (file_exists($lang_language_dir.$lang_compiled_dir."language_interface.inc")){ require_once($lang_language_dir.$lang_compiled_dir."language_interface.inc"); require_once($lang_language_dir.$lang_compiled_dir.$lang_project_default.".po.inc"); $default_language_lookup_array=$language_lookup_array; //Find out which language to use (todo: iterate trough list instead of picking first out: $client_language=strtolower(substr($HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"],0,2)); if ($client_language!=$lang_project_default){ if (file_exists($lang_language_dir.$lang_compiled_dir.$client_language.".po.inc")){ //If we have the language require_once($lang_language_dir.$lang_compiled_dir.$client_language.".po.inc"); //Include it } } } else { language_log("Could not load language interface.",2); echo "ERROR: Could not load language interface. This is a fatal error, exitting."; flush; exit; }; ?>