GetXMLTree( $fname ); if (file_exists($fname)){ $xmlstring = file_get_contents($fname); } else { echo 'FILE DOES NOT EXIST: ' . $fname; return 0; } $xmlstring = icewarp_utf8_bad_replace($xmlstring); // replace new lines in string values with pipes $xmlstring = preg_replace( "/([^>] *)\\r\\n/m", "\\1|", $xmlstring ); $langxml = $xmlparser->GetXMLTreeFromString( $xmlstring ); //echo "
";
// process forms
foreach ( $langxml['APPLICATION'][0]['FORMS'][0]['FORM'] as $form ) {
$formID = $form["ATTRIBUTES"]["ID"];
$array[$formID] = getValue($form["ATTRIBUTES"]["CAPTION"]);
if ( count( $form['ITEM'] ) ) {
foreach ( $form['ITEM'] as $item ) {
if ( strval($item['ATTRIBUTES']['CLASS']) == "tcombobox" ||
strval($item['ATTRIBUTES']['CLASS']) == "tcustomlistview" ||
strval($item['ATTRIBUTES']['CLASS']) == "tchecklistbox" ||
strval($item['ATTRIBUTES']['CLASS']) == "tadvancedheaderlist" ) {
// this item is a complex (multiline) item with multiple subitems
$array[$formID."_".$item['ATTRIBUTES']['ID']] = getValue($item['ATTRIBUTES']['ITEMSTEXT']);
}
else {
$array[$formID."_".$item['ATTRIBUTES']['ID']] = getValue($item['ATTRIBUTES']['CAPTION']);
}
}
}
}
// process menu items
foreach ( $langxml['APPLICATION'][0]['MENU'][0]['SECTION'] as $menu ) {
$menuID = $menu["ATTRIBUTES"]["ID"];
if($menuID=='advanced'){
if ( count( $menu['ITEM'] ) ) {
foreach ( $menu['ITEM'] as $item ) {
$array["TTntMenuItems_".$item['ATTRIBUTES']['ID']] = getValue($item['ATTRIBUTES']['TITLE']);
}
}
}
}
// process global strings
foreach ( $langxml['APPLICATION'][0]['STRINGS'][0]['STRING'] as $string ) {
$stringID = $string["ATTRIBUTES"]["ID"];
if ( count( $string['ITEM'] ) ) {
foreach ( $string['ITEM'] as $item ) {
$array[$stringID."_".$item['ATTRIBUTES']['ID']] = getValue($item['ATTRIBUTES']['VALUE']);
}
}
}
return $array;
}
/* ---------------------------------------------------------------------------------------
SaveALang function takes a flat array of strings containing the language data and writes
them down into a php file as a definition of that array.
--------------------------------------------------------------------------------------- */
function SaveALang( $array, $fname )
{
if ( ($fh = fopen( $fname, "wt" ) ) === FALSE ) return -1;
fprintf( $fh, " "\\\\", "\"" => "\\\"");
foreach ( $array as $key => $val ) {
$id = strtr( $key, $replacement );
$string = strtr( $val, $replacement );
fprintf( $fh, '$alang["%s"] = "%s";'."\n", $id, $string );
}
fprintf( $fh, "?>" );
fclose( $fh );
return 0;
}
function ConvertOne($langFN,$alangFN)
{
// load the .XML
$lang = LoadLang( $langFN );
//echo ""; print_r( $lang ); echo "
";
// save as .HTML
if ( SaveALang( $lang, $alangFN ) ) echo "Unable to save the language data.
";
else echo "Language file '$langFN' successfully converted to '$alangFN'.
";
}
function ConvertDir($in,$ou)
{
if ($dh = opendir($in))
{
while (($file = readdir($dh)) !== false)
{
if (filetype($in . $file)!='dir') continue;
if ($file[0]=='.') continue;
echo "\n\n".$file."\n";
if(!is_dir($ou.$file)) mkdir($ou.$file);
ConvertOne($in.$file.'\data.xml',$ou.$file.'\alang.html');
}
closedir($dh);
}
}
$langFN = "data.xml";
$alangFN = "alang.html";
if ( isset($lang) && strlen($lang) ) $langFN = $lang;
if ( isset($alang) && strlen($alang) ) $alangFN = $alang;
if ( isset($argv[1]) && strlen($argv[1]) ) $inputDir = $argv[1];
if ( isset($argv[2]) && strlen($argv[2]) ) $outputDir = $argv[2];
if( $inputDir && $outputDir)
{
if(is_dir($inputDir))
ConvertDir($inputDir,$outputDir);
else
ConvertOne($inputDir,$outputDir);
}
else
ConvertOne($langFN,$alangFN);
?>