11<?php /*
22+----------------------------------------------------------------------+
3- | Copyright (c) 1997-2025 The PHP Group |
3+ | Copyright (c) 1997-2026 The PHP Group |
44+----------------------------------------------------------------------+
55| This source file is subject to version 3.01 of the PHP license, |
66| that is bundled with this package in the file LICENSE, and is |
3838 $ dos2unix = true ;
3939 $ arg = null ;
4040 }
41+ else
42+ $ arg = str_replace ( '\\' , '/ ' , $ arg );
4143}
42- $ argv = array_filter ( $ argv );
44+ $ paths = array_filter ( $ argv );
45+ if ( count ( $ paths ) == 0 )
46+ print_usage_exit ();
4347
44- foreach ( $ argv as $ arg )
48+ foreach ( $ paths as $ path )
4549{
46- if ( file_exists ( $ arg ) )
50+ $ dnt = true ;
51+ if ( $ path == 'en ' || str_ends_with ( $ path , '/en ' ) )
52+ $ dnt = false ;
53+
54+ if ( file_exists ( $ path ) )
4755 {
48- if ( is_file ( $ arg ) )
49- testFile ( $ arg );
50- if ( is_dir ( $ arg ) )
51- testDir ( $ arg );
56+ if ( is_file ( $ path ) )
57+ testFile ( $ path , $ dnt );
58+ if ( is_dir ( $ path ) )
59+ testDir ( $ path , $ dnt );
5260 continue ;
5361 }
54- echo "Path does not exist: $ arg \n" ;
62+ echo "Path does not exist: $ path \n" ;
5563}
5664
5765function print_usage_exit ( $ cmd )
@@ -87,7 +95,7 @@ function setup( string & $prefix , string & $suffix , string & $extra )
8795 libxml_clear_errors ();
8896}
8997
90- function testFile ( string $ filename , bool $ fragment = false )
98+ function testFile ( string $ filename , bool $ checkDnt , bool $ fragmentDir = false )
9199{
92100 $ contents = file_get_contents ( $ filename );
93101
@@ -96,7 +104,7 @@ function testFile( string $filename , bool $fragment = false )
96104 echo "Wrong XML file: \n" ;
97105 echo " Issue: XML file with BOM. Several tools may misbehave. \n" ;
98106 echo " Path: $ filename \n" ;
99- echo " Hint: You can try autofix this with 'doc-base/scripts/broken.php --dos2unix langdir'. \n" ;
107+ echo " Hint: You can try auto fix this with 'doc-base/scripts/broken.php --dos2unix langdir'. \n" ;
100108 echo "\n" ;
101109 autofix_dos2unix ( $ filename );
102110 }
@@ -106,7 +114,16 @@ function testFile( string $filename , bool $fragment = false )
106114 echo "Wrong XML file: \n" ;
107115 echo " Issue: XML file contains \\r. Several tools may misbehave. \n" ;
108116 echo " Path: $ filename \n" ;
109- echo " Hint: You can try autofix this with 'doc-base/scripts/broken.php --dos2unix langdir'. \n" ;
117+ echo " Hint: You can try auto fix this with 'doc-base/scripts/broken.php --dos2unix langdir'. \n" ;
118+ echo "\n" ;
119+ autofix_dos2unix ( $ filename );
120+ }
121+
122+ if ( $ checkDnt && strpos ( $ contents , '<?do-not-translate?> ' ) !== false )
123+ {
124+ echo "File marked do-not-translate in translation: \n" ;
125+ echo " Issue: Manual build may fail. \n" ;
126+ echo " Path: $ filename \n" ;
110127 echo "\n" ;
111128 autofix_dos2unix ( $ filename );
112129 }
@@ -121,7 +138,7 @@ function testFile( string $filename , bool $fragment = false )
121138 $ doc ->substituteEntities = false ;
122139 libxml_use_internal_errors ( true );
123140
124- if ( $ fragment )
141+ if ( $ fragmentDir )
125142 $ contents = "<f> {$ contents }</f> " ;
126143 $ doc ->loadXML ( $ contents );
127144
@@ -152,18 +169,18 @@ function testFile( string $filename , bool $fragment = false )
152169 }
153170}
154171
155- function testDir ( string $ dir )
172+ function testDir ( string $ dir , bool $ checkDnt )
156173{
157174 $ dir = realpath ( $ dir );
158175 $ files = scandir ( $ dir );
159- $ fragment = false ;
176+ $ fragmentDir = false ;
160177 $ subdirs = [];
161178
162179 foreach ( $ files as $ file )
163180 {
164181 if ( $ file == ".xmlfragmentdir " )
165182 {
166- $ fragment = true ;
183+ $ fragmentDir = true ;
167184 continue ;
168185 }
169186 if ( $ file [0 ] == ". " )
@@ -178,11 +195,11 @@ function testDir( string $dir )
178195 }
179196
180197 if ( str_ends_with ( $ fullpath , ".xml " ) )
181- testFile ( $ fullpath , $ fragment );
198+ testFile ( $ fullpath , $ checkDnt , $ fragmentDir );
182199 }
183200
184201 foreach ( $ subdirs as $ dir )
185- testDir ( $ dir );
202+ testDir ( $ dir , $ checkDnt );
186203}
187204
188205function autofix_dos2unix ( string $ filename )
0 commit comments