. $lang_language_dir = "../languages/"; $lang_translations_dir = "translations/"; $lang_prj_translations_dir = "project_specific_translations/"; $lang_compiled_dir = "compiled/"; $lang_log_level = 1; // Get a list of compiled languages by scanning the compiled/ dir // @returns A list of languages that have been compiled // function get_supported_languages() { global $lang_language_dir, $lang_compiled_dir; $list = array(); if (!is_dir($lang_language_dir.$lang_compiled_dir)) { echo "\"".$lang_language_dir.$lang_compiled_dir."\" is not a directory. Please consult the documentation for correctly setting up the translation system."; exit; } $dh = opendir($lang_language_dir.$lang_compiled_dir); if (!$dh) die("can't open language dir"); while ($file = readdir($dh)) { if (substr($file, -7) != ".po.inc") continue; if (is_numeric(substr($file, 0, 5))) continue; $list[] = substr($file, 0, -7); } return $list; } // generate PHP files defining translation arrays. // For example, the file "ca.po.inc" would contain entries of the form // $language_lookup_array["ca"]["Default"] = "Defecte"; // // Append to these files if they already exist // (this may get done for both generic and project-specific translations) // // @param langdir The language base directory // @param transdir The location of the .po files to compile relative to langdir // @param compdir The output location relative to langdir // function build_translation_array_files($langdir, $transdir, $compdir) { // Run through each language and compile their lookup arrays. // if (!is_dir($langdir.$transdir)) { //debug("$info_dir not found or is not a directory"); } $dh = opendir($langdir.$transdir); if (!$dh) die("can't open translation dir"); while (($file = readdir($dh)) !== false) { if ($file==".." || $file==".") { continue; } // only do files ending in .po if (substr($file,-3) != ".po"){ //debug("File $file with unknown extension found in $info_dir"); continue; } language_log( "-------------Compiling $transdir$file------------", 0 ); $language = parse_po_file($langdir.$transdir.$file); if (!$language){ language_log( "WARNING: Could not parse language ".$file ); continue; } $path = $langdir.$compdir.$file.".inc"; if (file_exists($path)) { $fh = fopen($path, "a"); } else { $fh = fopen($path, "w"); fwrite($fh, " $value){ if ($value !== "") { // Skip if the msgstr is empty fwrite($fh, "\$language_lookup_array[\"".str_replace("\"", "\\\"", substr($file,0,-3))."\"][\"".$key."\"] = \"".$value."\";\n"); } } // don't write \?\> - may append fclose($fh); } closedir($dh); } // Parses a gettext .po-file into an associative PHP array. // @param file The file to parse // checking for inconsistencies if needed. // function parse_po_file($file) { $translation_file = file($file); $first_entry = true; $current_token_text=""; $current_token =""; $parsing_token = false; $parsing_text = false; $output = array(); for ($i=0; $i= $lang_log_level){ echo gmdate("Y-m-d H:i:s", time())." ".$msg." ".$message."\n"; } } // Make a list of languages which the user prefers // (by looking at cookies and browser settings) // cookies have highest priority. if (isset($_COOKIE['lang'])){ $language_string = $_COOKIE['lang'].","; } else { $language_string = ''; } if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) { $language_string .= strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]); } // Find out which language to use by iterating through list // The list is comma-separated, so split it into an array of the following type: // Array ( // [0] => da // [1] => en-us;q=0.7 // [2] => en;q=0.3 // ) $client_languages = explode(",", $language_string); // A language is either defined as primary-secondary or primary. // It can also have a quality attribute set, // which orders the languages in a user preferred ordering. // Since this is usally the same order as the array indices // we just ignore this attribute (TODO: don't ignore this attribute) // A missing quality attribute means q=1 $languages_in_use = array(); // Loop over languages that the client requests // for ($i=0; $i2) && (substr($client_languages[$i], 2, 1) == "_" || substr($client_languages[$i], 2, 1) == "-") ){ // If this is defined as primary-secondary, represent it as xx_YY // $language = substr( $client_languages[$i], 0, 2)."_".strtoupper(substr($client_languages[$i], 3, 2) ); // And also check for the primary language // $language2 = substr($client_languages[$i], 0, 2); } else { // else just use xx // $language = substr($client_languages[$i], 0, 2); $language2 = null; } // if main language is english, look no further // if ($i == 0 && $language == 'en') { break; } // If we have a translation for the language, include it // $file_name = $lang_language_dir.$lang_compiled_dir.$language.".po.inc"; if (file_exists($file_name)) { if (!in_array($language, $languages_in_use)){ require_once($file_name); $languages_in_use[] = $language; } } if ($language2) { $file_name = $lang_language_dir.$lang_compiled_dir.$language2.".po.inc"; if (file_exists($file_name)) { if (!in_array($language2, $languages_in_use)){ require_once($file_name); $languages_in_use[] = $language2; } } } } $GLOBALS['languages_in_use'] = $languages_in_use; // for Drupal $cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit ?>