From b2651c3628316856d06d627b5c5ef3ad1953ae37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Sat, 27 Jun 2026 13:28:19 -0300 Subject: [PATCH 1/2] Fix counters, detailed messages and comments --- scripts/text-entities.php | 50 ++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/scripts/text-entities.php b/scripts/text-entities.php index 418ace6b30..1333be38c8 100644 --- a/scripts/text-entities.php +++ b/scripts/text-entities.php @@ -96,7 +96,9 @@ */ -const PARTIAL_IMPL = true; // For while XML Entities are not fully implanted in all languages +// For while XML Entities are not fully implanted in all languages +// Can be removed when all languages have an doc-lang/entities dir. +const PARTIAL_IMPL = true; ini_set( 'display_errors' , 1 ); ini_set( 'display_startup_errors' , 1 ); @@ -106,23 +108,21 @@ $langs = []; $debug = false; +$argv0 = array_shift( $argv ); $usage = in_array( '--help' , $argv ) || in_array( '-h' , $argv ); -if ( count( $argv ) < 2 || $usage ) -{ - print "\nUsage: {$argv[0]} langCode [langCode] [--debug]\n\n"; - if ( $usage ) - exit( 0 ); - else - exit( 1 ); -} -array_shift( $argv ); +if ( count( $argv ) == 0 || $usage ) + usage_and_exit( $argv0 ); + foreach( $argv as $arg ) if ( $arg == "--debug" ) $debug = true; else $langs[] = $arg; +if ( count( $langs ) == 0 ) + usage_and_exit( $argv0 ); + print "Running text-entities.php... "; if ( $debug ) print "\n"; @@ -140,15 +140,27 @@ Entities::writeOutputFile(); Entities::checkReplaces( $debug ); -echo "done: " , Entities::$countTotalGenerated , " entities"; +print "done: " . Entities::$countTotalGenerated . " entities"; if ( Entities::$countTransFailures > 0 ) - echo ", " , Entities::$countTransFailures , " untranslated"; + print ", " . Entities::$countTransFailures . " untranslated"; if ( Entities::$countOtherFailures > 0 ) - echo ", " , Entities::$countOtherFailures , " other failures"; -echo ".\n"; + print ", " . Entities::$countOtherFailures . " errors"; +print ".\n"; +if ( Entities::$countOtherFailures > 0 && ! $debug ) +{ + $langs[] = '--debug'; + $opts = implode( ' ' , $langs ); + print "(Run 'php $argv0 $opts' for details.\n"; +} exit; +function usage_and_exit( $argv0 ) +{ + print "\nUsage: $argv0 langCode [langCode] [--debug]\n\n"; + exit( 0 ); +} + enum EntityCheck { case Unique; // Expected once @@ -189,9 +201,10 @@ static function put( string $path , string $name , string $text , bool $unique = if ( $remove ) Entities::$remove[ $name ] = $name; - if ( ! isset( Entities::$nameCount[ $name ] ) ) - Entities::$nameCount[ $name ] = 0; - Entities::$nameCount[ $name ]++; + if ( isset( Entities::$nameCount[ $name ] ) ) + Entities::$nameCount[ $name ] += 1; + else + Entities::$nameCount[ $name ] = 1; } static function truncateOutputFile() @@ -281,7 +294,6 @@ function loadDirEntities( string $dir ) $dir = realpath( $dir ); $files = scandir( $dir ); foreach( $files as $file ) - foreach( $files as $file ) { $path = realpath( "$dir/$file" ); @@ -457,7 +469,7 @@ function outputFiles( string $filename , array $entities ) if ( file_exists( $path ) ) { - echo "\nDuplicated text-entity file: '{$path}'.\n"; + print "\nDuplicated text-entity file: '{$path}'.\n"; exit( 1 ); } From 18f6679cf56c9d25ce781b95e681e5dfc957f63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20L=20F=20S=20Bacci?= Date: Sat, 27 Jun 2026 16:37:45 -0300 Subject: [PATCH 2/2] Simetric messages, simplify code --- scripts/text-entities.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/text-entities.php b/scripts/text-entities.php index 1333be38c8..a1306dbd3c 100644 --- a/scripts/text-entities.php +++ b/scripts/text-entities.php @@ -111,16 +111,13 @@ $argv0 = array_shift( $argv ); $usage = in_array( '--help' , $argv ) || in_array( '-h' , $argv ); -if ( count( $argv ) == 0 || $usage ) - usage_and_exit( $argv0 ); - foreach( $argv as $arg ) if ( $arg == "--debug" ) $debug = true; else $langs[] = $arg; -if ( count( $langs ) == 0 ) +if ( count( $argv ) == 0 || $usage ) usage_and_exit( $argv0 ); print "Running text-entities.php... "; @@ -151,7 +148,7 @@ { $langs[] = '--debug'; $opts = implode( ' ' , $langs ); - print "(Run 'php $argv0 $opts' for details.\n"; + print "(Run 'php $argv0 $opts' for details.)\n"; } exit;