diff --git a/scripts/translation/libqa/OutputBuffer.php b/scripts/translation/libqa/OutputBuffer.php index 2c8a5b057..d620af298 100644 --- a/scripts/translation/libqa/OutputBuffer.php +++ b/scripts/translation/libqa/OutputBuffer.php @@ -67,7 +67,7 @@ public function addDiff( string $text , int $sourceCount , int $targetCount ) public function addFooter( string $text ) { - $this->footer[] = $text; + // $this->footer[] = $text; } public function addLine() diff --git a/scripts/translation/libqa/SyncFileList.php b/scripts/translation/libqa/SyncFileList.php index 77c2e6328..7498c5004 100644 --- a/scripts/translation/libqa/SyncFileList.php +++ b/scripts/translation/libqa/SyncFileList.php @@ -31,7 +31,7 @@ static function load() } $lang = trim( file_get_contents( $file ) ); - $cache = __DIR__ . "/../../../temp/$lang.oklist"; + $cache = __DIR__ . "/../../../temp/qaxml.files.$lang"; if ( file_exists( $cache ) ) { @@ -47,7 +47,12 @@ static function load() foreach( $revdata->fileDetail as $file ) { - if ( $file->status != RevcheckStatus::TranslatedOk ) + $source = "{$revcheck->sourceDir}/{$file->path}/{$file->name}"; + $target = "{$revcheck->targetDir}/{$file->path}/{$file->name}"; + + if ( ! file_exists( $source ) ) + continue; + if ( ! file_exists( $target ) ) continue; $item = new SyncFileItem(); @@ -57,6 +62,9 @@ static function load() $list[] = $item; } + if ( count( $list ) == 0 ) + throw new Exception( "No files found. Called from wrong directory?" ); + $contents = gzencode( serialize( $list ) ); file_put_contents( $cache , $contents ); diff --git a/scripts/translation/libqa/XmlFrag.php b/scripts/translation/libqa/XmlFrag.php index a940db12b..42d2fbc6c 100644 --- a/scripts/translation/libqa/XmlFrag.php +++ b/scripts/translation/libqa/XmlFrag.php @@ -44,16 +44,16 @@ static function loadXmlFragmentFile( string $filename ) [ $doc , $ent , $err ] = XmlFrag::loadXmlFragmentText( $contents , "" ); if ( count( $err ) == 0 ) - return [ $doc , $err ]; + return [ $doc , $ent , $err ]; $dtd = "\n\n"; $dtd .= "]>\n"; - [ $doc , $ent , $err ] = XmlFrag::loadXmlFragmentText( $contents , $dtd ); + [ $doc , $ign , $err ] = XmlFrag::loadXmlFragmentText( $contents , $dtd ); - return [ $doc , $err ]; + return [ $doc , $ent , $err ]; } static function loadXmlFragmentText( string $contents , string $dtd ) diff --git a/scripts/translation/qaxml-sync-attributes.php b/scripts/translation/qaxml-sync-attributes.php index 4576e59cb..4280d831c 100644 --- a/scripts/translation/qaxml-sync-attributes.php +++ b/scripts/translation/qaxml-sync-attributes.php @@ -28,8 +28,8 @@ $target = $file->targetDir . '/' . $file->file; $output = new OutputBuffer( "# qaxml.a" , $target , $ignore ); - [ $s , $e ] = XmlFrag::loadXmlFragmentFile( $source ); - [ $t , $e ] = XmlFrag::loadXmlFragmentFile( $target ); + [ $s , $_ , $_ ] = XmlFrag::loadXmlFragmentFile( $source ); + [ $t , $_ , $_ ] = XmlFrag::loadXmlFragmentFile( $target ); $s = XmlFrag::listNodes( $s , XML_ELEMENT_NODE ); $t = XmlFrag::listNodes( $t , XML_ELEMENT_NODE ); @@ -43,9 +43,9 @@ $match = array(); foreach( $s as $v ) - $match[$v] = array( 0 , 0 ); + $match[$v] = [ 0 , 0 ]; foreach( $t as $v ) - $match[$v] = array( 0 , 0 ); + $match[$v] = [ 0 , 0 ]; foreach( $s as $v ) $match[$v][0] += 1; diff --git a/scripts/translation/qaxml-sync-entities.php b/scripts/translation/qaxml-sync-entities.php new file mode 100644 index 000000000..a2cbe9f35 --- /dev/null +++ b/scripts/translation/qaxml-sync-entities.php @@ -0,0 +1,57 @@ + | ++----------------------------------------------------------------------+ + +# Description + +Compare XML entities usage between two XML leaf/fragment files. */ + +require_once __DIR__ . '/libqa/all.php'; + +$ignore = new OutputIgnore( $argv ); // always first, may exit. +$list = SyncFileList::load(); + +foreach ( $list as $file ) +{ + $source = $file->sourceDir . '/' . $file->file; + $target = $file->targetDir . '/' . $file->file; + $output = new OutputBuffer( "# qaxml.e" , $target , $ignore ); + + [ $_ , $s , $_ ] = XmlFrag::loadXmlFragmentFile( $source ); + [ $_ , $t , $_ ] = XmlFrag::loadXmlFragmentFile( $target ); + + if ( implode( "\n" , $s ) == implode( "\n" , $t ) ) + continue; + + $match = array(); + + foreach( $s as $v ) + $match[$v] = [ 0 , 0 ]; + foreach( $t as $v ) + $match[$v] = [ 0 , 0 ]; + + foreach( $s as $v ) + $match[$v][0] += 1; + foreach( $t as $v ) + $match[$v][1] += 1; + + foreach( $match as $k => $v ) + { + if ( $v[0] == $v[1] ) + continue; + $output->addDiff( $k , $v[0] , $v[1] ); + } + + $output->print(); +}