From a20180aded2f230ee1b3ba00a4af68d2f79231c8 Mon Sep 17 00:00:00 2001 From: stan Date: Wed, 25 May 2011 09:13:47 +0000 Subject: [PATCH] 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 --- web/lang/updateLangs.php | 44 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/web/lang/updateLangs.php b/web/lang/updateLangs.php index e4ff1265e..5aa1925b8 100644 --- a/web/lang/updateLangs.php +++ b/web/lang/updateLangs.php @@ -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"; } ?>