function parse_translation($DOCDIR, $LANG, $MAINT) { global $files_by_mark; // Path to find translation.xml file, set default values, // in case we can't find the translation file $translation_xml = $DOCDIR . $LANG . "/translation.xml"; $output_charset = 'iso-8859-1'; $translation = array("intro" => "", "persons" => array(), "files" => array(), "allfiles" => array()); // Check for file availability, return with default // values, if we cannot find the file if (!@file_exists($translation_xml)) { return array($output_charset, $translation); } // Else go on, and load in the file, replacing all // space type chars with one space $txml = join("", file($translation_xml)); $txml = preg_replace("/\\s+/", " ", $txml); // Get intro text (different for a persons info and // for a whole group info page) if (empty($MAINT)) { preg_match("!<intro>(.+)</intro>!s", $txml, $match); $translation["intro"] = trim($match[1]); } else { $translation["intro"] = "Personal Statistics for " . $MAINT; } // Get encoding for the output, from the translation.xml // file encoding (should be the same as the used encoding // in HTML) preg_match("!<\\?xml(.+)\\?>!U", $txml, $match); $xmlinfo = parse_attr_string($match); $output_charset = $xmlinfo[1]["encoding"]; // Get persons list preg pattern, only check for a specific // maintainer, if the users asked for it if (empty($MAINT)) { $pattern = "!<person(.+)/\\s?>!U"; } else { $pattern = "!<person([^<]+nick=\"" . $MAINT . "\".+)/\\s?>!U"; } // Find all persons matching the pattern preg_match_all($pattern, $txml, $matches); $translation['persons'] = parse_attr_string($matches[1]); // Get list of work in progress files if (empty($MAINT)) { // Get all wip files preg_match_all("!<file(.+)/\\s?>!U", $txml, $matches); $translation['files'] = parse_attr_string($matches[1]); // Provide info about number of WIP files $files_by_mark[REV_WIP] += count($translation['files']); } else { // Only check for a specific maintainer, if we were asked to preg_match_all("!<file([^<]+person=\"" . $MAINT . "\".+)/\\s?>!U", $txml, $matches); $translation['files'] = parse_attr_string($matches[1]); // Other maintainers wip files need to be cleared from // available files list in the future, so store that info too. preg_match_all("!<file(.+)/\\s?>!U", $txml, $matches); $translation['allfiles'] = parse_attr_string($matches[1]); // Provide info about number of WIP files $files_by_mark[REV_WIP] += count($translation['allfiles']); } // Return with collected info in two vars return array($output_charset, $translation); }
/** * Functions **/ function parse_translation($lang) { global $SQL_BUFF, $DOCS, $LANGUAGES; echo "Parsing intro..\n"; // Path to find translation.xml file, set default values, // in case we can't find the translation file $translation_xml = $DOCS . $lang . "/translation.xml"; $intro = "No intro available for the {$LANGUAGES[$lang]} translation of the manual."; $charset = 'iso-8859-1'; if (file_exists($translation_xml)) { // Else go on, and load in the file, replacing all // space type chars with one space $txml = join("", file($translation_xml)); $txml = preg_replace("/\\s+/", " ", $txml); // Get encoding for the output, from the translation.xml // file encoding (should be the same as the used encoding // in HTML) if (preg_match("!<\\?xml(.+)\\?>!U", $txml, $match)) { $xmlinfo = parse_attr_string($match); if (isset($xmlinfo[1]["encoding"])) { $charset = $xmlinfo[1]["encoding"]; } } // Get intro text if (preg_match("!<intro>(.+)</intro>!s", $txml, $match)) { $intro = SQLite3::escapeString(@iconv($charset, 'UTF-8//IGNORE', trim($match[1]))); } } $SQL_BUFF .= "INSERT INTO description VALUES ('{$lang}', '{$intro}');\n"; if (isset($txml)) { // Find all persons matching the pattern if (preg_match_all("!<person (.+)/\\s?>!U", $txml, $matches)) { $default = array('vcs' => 'n/a', 'nick' => 'n/a', 'editor' => 'n/a', 'email' => 'n/a', 'name' => 'n/a'); $persons = parse_attr_string($matches[1]); foreach ($persons as $person) { $person = array_merge($default, $person); $nick = SQLite3::escapeString($person['nick']); $name = SQLite3::escapeString(@iconv($charset, 'UTF-8//IGNORE', $person['name'])); $email = SQLite3::escapeString($person['email']); $vcs = SQLite3::escapeString($person['vcs']); $editor = SQLite3::escapeString($person['editor']); $SQL_BUFF .= "INSERT INTO translators VALUES ('{$lang}', '{$nick}', '{$name}', '{$email}', '{$vcs}', '{$editor}');\n"; } } // Get list of work in progress files if (preg_match_all("!<file(.+)/\\s?>!U", $txml, $matches)) { $files = parse_attr_string($matches[1]); foreach ($files as $file) { $name = SQLite3::escapeString($file['name']); $person = SQLite3::escapeString($file['person']); $type = SQLite3::escapeString(isset($file['type']) ? $file['type'] : 'translation'); $SQL_BUFF .= "INSERT INTO wip VALUES ('{$lang}', '{$name}', '{$person}', '{$type}');\n"; } } } }