Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions scripts/text-entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -106,23 +108,18 @@

$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 );
foreach( $argv as $arg )
if ( $arg == "--debug" )
$debug = true;
else
$langs[] = $arg;

if ( count( $argv ) == 0 || $usage )
usage_and_exit( $argv0 );

print "Running text-entities.php... ";
if ( $debug )
print "\n";
Expand All @@ -140,15 +137,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
Expand Down Expand Up @@ -189,9 +198,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()
Expand Down Expand Up @@ -281,7 +291,6 @@ function loadDirEntities( string $dir )
$dir = realpath( $dir );
$files = scandir( $dir );
foreach( $files as $file )
foreach( $files as $file )
{
$path = realpath( "$dir/$file" );

Expand Down Expand Up @@ -457,7 +466,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 );
}

Expand Down