diff --git a/scripts/broken.php b/scripts/broken.php index b26d143c19..c4a04d5416 100644 --- a/scripts/broken.php +++ b/scripts/broken.php @@ -24,10 +24,6 @@ require_once __DIR__ . '/translation/lib/XmlErrorFilter.php'; -ini_set( 'display_errors' , 1 ); -ini_set( 'display_startup_errors' , 1 ); -error_reporting( E_ALL ); - if ( count( $argv ) < 2 ) print_usage_exit( $argv[0] ); array_shift( $argv ); @@ -49,16 +45,15 @@ foreach( $paths as $path ) { - $dnt = true; - if ( $path == 'en' || str_ends_with( $path , '/en' ) ) - $dnt = false; - if ( file_exists( $path ) ) { + $checkDnt = ! file_exists( "$path/manual.xml" ); + if ( is_file( $path ) ) - testFile( $path , $dnt ); + testFile( $path , $checkDnt ); if ( is_dir( $path ) ) - testDir( $path , $dnt ); + testDir( $path , $checkDnt ); + continue; } echo "Path does not exist: $path\n"; diff --git a/scripts/text-entities.php b/scripts/text-entities.php index 75f6bb79ec..ac27d49ad8 100644 --- a/scripts/text-entities.php +++ b/scripts/text-entities.php @@ -96,14 +96,6 @@ */ -// 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 ); -error_reporting( E_ALL ); - Entities::truncateOutputFile(); $langs = []; @@ -129,7 +121,7 @@ $entDir = __DIR__ . "/../../$lang/entities"; $refDir = __DIR__ . "/../../$lang/reference"; - loadDirEntities( $entDir ); + loadDirEntities( $entDir , $lang ); loadDirRecurse( $refDir ); Entities::$countLanguages++; } @@ -214,7 +206,20 @@ static function truncateOutputFile() static function writeOutputFile() { - outputFiles( Entities::$filename , Entities::$merged ); + $file = fopen( Entities::$filename , "w" ); + fputs( $file , "\n\n\n" ); + + foreach( Entities::$merged as $name => $entity ) + { + $name = $entity->name; + $body = $entity->text; + + $escaped = str_replace( "'" , ''' , $body ); + + fputs( $file , "\n\n" ); + } + + fclose( $file ); } static function checkReplaces( bool $debug ) @@ -272,21 +277,12 @@ static function checkReplaces( bool $debug ) } } -function loadDirEntities( string $dir ) +function loadDirEntities( string $dir , string $lang ) { if ( realpath( $dir ) === false || ! is_dir( $dir ) ) { - if ( PARTIAL_IMPL ) - { - global $lang; - print "(skiped $lang/entities) "; - return; - } - else - { - print "\n Not a directory: $dir\n"; - exit( 1 ); - } + print "(missing $lang/entities) "; + return; } $dir = realpath( $dir ); @@ -421,62 +417,3 @@ function loadEntitySingle( string $path ) Entities::put( $path , $name , $text ); } - -function outputFiles( string $filename , array $entities ) -{ - $file = fopen( $filename , "w" ); - fputs( $file , "\n\n\n" ); - - $sepFileDir = __DIR__ . "/../temp/text-entities/"; - - if ( file_exists( $sepFileDir ) == false ) - mkdir( $sepFileDir , recursive: true ); - - foreach( $entities as $name => $entity ) - { - $name = $entity->name; - $body = $entity->text; - - $quote = "'"; - $count = 0; - - if ( str_contains( $body , "'" ) ) - { - $quote = '"'; - $count++; - } - if ( str_contains( $body , '"' ) ) - { - $quote = "'"; - $count++; - } - - if ( $count < 2 ) - { - // Fast path for single or no quote: - // entity body directly quoted on output file. - - fputs( $file , "\n\n" ); - continue; - } - - // Slow path: entity body as an external file, - // as to avoid (re)quotation hell. - - $path = $sepFileDir . "/{$entity->name}.xml"; - - if ( file_exists( $path ) ) - { - print "\nDuplicated text-entity file: '{$path}'.\n"; - exit( 1 ); - } - - // realpath() only after file creation - - file_put_contents( $path , $body ); - $path = realpath( $path ); - fputs( $file , "\n\n" ); - } - - fclose( $file ); -}