From 6b91ff524ba974b01dd686ca687ae9b7eca99eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Tue, 11 Feb 2025 16:33:43 -0300 Subject: [PATCH] Command line option to ignore entity by name --- scripts/translation/libqa/ArgvParser.php | 12 ++++++--- scripts/translation/qaxml-sync-entities.php | 29 +++++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/scripts/translation/libqa/ArgvParser.php b/scripts/translation/libqa/ArgvParser.php index 6739c7fa2..a90570c8c 100644 --- a/scripts/translation/libqa/ArgvParser.php +++ b/scripts/translation/libqa/ArgvParser.php @@ -30,10 +30,15 @@ public function __construct( array $argv ) $this->used = array_fill( 0 , count( $argv ) , false ); } - public function at( int $pos ) : string + public function use( string $arg ) : void { - $this->used[ $pos ] = true; - return $this->argv[ $pos ]; + foreach ( $this->argv as $pos => $value ) + if ( $arg == $value && $this->used[ $pos ] == false ) + { + $this->used[ $pos ] = true; + return; + } + throw new Exception( "Unused '$arg' not found." ); } public function consume( string $equals = null , string $prefix = null , int $position = -1 ) : string|null @@ -41,7 +46,6 @@ public function consume( string $equals = null , string $prefix = null , int $po $args = $this->argv; foreach ( $args as $pos => $arg ) { - if ( $arg == null ) continue; diff --git a/scripts/translation/qaxml-sync-entities.php b/scripts/translation/qaxml-sync-entities.php index f964522bc..ec19eac2a 100644 --- a/scripts/translation/qaxml-sync-entities.php +++ b/scripts/translation/qaxml-sync-entities.php @@ -23,9 +23,19 @@ $ignore = new OutputIgnore( $argv ); // may exit. $urgent = $argv->consume( "--urgent" ) != null; -$list = SyncFileList::load(); +$ents = []; +foreach( $argv->residual() as $ent ) +{ + if ( strlen( $ent ) > 2 && $ent[0] == '-' && $ent[1] != '-' ) + { + $ents[] = '&' . substr( $ent , 1) . ';'; + $argv->use( $ent ); + } +} $argv->complete(); +$list = SyncFileList::load(); + foreach ( $list as $file ) { $source = $file->sourceDir . '/' . $file->file; @@ -41,19 +51,23 @@ if ( implode( "\n" , $s ) == implode( "\n" , $t ) ) continue; - $match = array(); + $sideCount = array(); foreach( $s as $v ) - $match[$v] = [ 0 , 0 ]; + $sideCount[$v] = [ 0 , 0 ]; foreach( $t as $v ) - $match[$v] = [ 0 , 0 ]; + $sideCount[$v] = [ 0 , 0 ]; foreach( $s as $v ) - $match[$v][0] += 1; + $sideCount[$v][0] += 1; foreach( $t as $v ) - $match[$v][1] += 1; + $sideCount[$v][1] += 1; + + foreach( $sideCount as $ent => $_ ) + if ( in_array( $ent , $ents ) ) + $sideCount[ $ent ] = [ 0 , 0 ]; - foreach( $match as $k => $v ) + foreach( $sideCount as $k => $v ) if ( $v[0] != $v[1] ) $output->addDiff( $k , $v[0] , $v[1] ); @@ -74,7 +88,6 @@ continue; } - $output->print(); }