Skip to content

Commit

Permalink
Command line option to ignore entity by name
Browse files Browse the repository at this point in the history
  • Loading branch information
André L F S Bacci committed Feb 11, 2025
1 parent 92d6874 commit 6b91ff5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
12 changes: 8 additions & 4 deletions scripts/translation/libqa/ArgvParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ 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
{
$args = $this->argv;
foreach ( $args as $pos => $arg )
{

if ( $arg == null )
continue;

Expand Down
29 changes: 21 additions & 8 deletions scripts/translation/qaxml-sync-entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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] );

Expand All @@ -74,7 +88,6 @@
continue;
}


$output->print();
}

Expand Down

0 comments on commit 6b91ff5

Please sign in to comment.