Updated to process other sections on top of SLANG

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@3362 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan
2011-05-25 09:13:47 +00:00
parent 2cb0ef57e1
commit a20180aded

View File

@@ -46,7 +46,7 @@ foreach ( $files as $file )
$token = preg_replace( "/\s/", "", ucwords( preg_replace( "/_/", " ", basename( $file, ".php" ) ) ) );
$code = $rawCode = file_get_contents( $file );
$code = $fileCode = file_get_contents( $file );
$code = preg_replace( "/zmVlang/", "zmVlang".$token, $code );
$code = preg_replace( "/^header.*$/m", "", $code );
$code = preg_replace( "/^setlocale.*$/m", "", $code );
@@ -63,13 +63,29 @@ foreach ( $files as $file )
require_once( $tmpFile );
unlink( $tmpFile );
$pattern = '/^(.+SLANG = array\(\n)(.+)(\);.+?)/sU';
updateSection( $fileCode, 'SLANG' );
updateSection( $fileCode, 'CLANG' );
updateSection( $fileCode, 'VLANG' );
if ( $fp = fopen( $newFile, "w" ) )
{
fwrite( $fp, $fileCode );
fclose( $fp );
}
rename( $newFile, $file );
}
function updateSection( &$code, $section )
{
global $termOffset, $commOffset, $modDate;
$pattern = '/^(.+'.$section.' = array\(\n)(.+)(\);.+?)/sU';
//echo "P:'$pattern'\n";
if ( !preg_match( $pattern, $rawCode, $fileParts ) )
die( "Can't find SLANG array\n" );
if ( !preg_match( $pattern, $code, $fileParts ) )
die( "Can't find '.$section.' array\n" );
//echo "F:'".$fileParts[2]."'\n";
if ( !preg_match_all( "/(\s+.+)\n/", $fileParts[2], $matches ) )
die( "Can't find SLANG terms\n" );
die( "Can't find '.$section.' terms\n" );
$terms = $matches[1];
$assocTerms = array();
@@ -79,9 +95,11 @@ foreach ( $files as $file )
die( "Can't find term name in '$term'\n" );
$assocTerms[$matches[1]] = $term;
}
foreach ( $enSLANG as $enName=>$enValue )
$enVar = $GLOBALS['en'.$section];
$langVar = $GLOBALS[$section];
foreach ( $enVar as $enName=>$enValue )
{
if ( empty($SLANG[$enName]) )
if ( empty($langVar[$enName]) )
{
print( "Got missing token '".$enName."'\n" );
$termPaddLen = max( $termOffset-(2+strlen($enName)), 0 );
@@ -89,22 +107,16 @@ foreach ( $files as $file )
$assocTerms[$enName] = " '".$enName."'".str_repeat(" ",$termPaddLen)."=> '$enValue', ".str_repeat(" ",$commPaddLen)."// Added - $modDate";
}
}
foreach ( $SLANG as $name=>$value )
foreach ( $langVar as $name=>$value )
{
if ( empty($enSLANG[$name]) )
if ( empty($enVar[$name]) )
{
print( "Got extraneous token '".$name."'\n" );
unset($assocTerms[$name]);
}
}
ksort( $assocTerms, SORT_STRING );
$newCode = $fileParts[1].join( "\n", array_values($assocTerms) )."\n".rtrim($fileParts[3])."\n";
if ( $fp = fopen( $newFile, "w" ) )
{
fwrite( $fp, $newCode );
fclose( $fp );
}
rename( $newFile, $file );
$code = $fileParts[1].join( "\n", array_values($assocTerms) )."\n".rtrim($fileParts[3])."\n";
}
?>