3535 'screen ' , 'seg ' , 'segtitle ' , 'synopsis ' ,
3636];
3737
38- const DEFAULT_MESSAGES = [
39- 'invalid ' => '<<INVALID>> ' ,
40- 'none ' => '(none) ' ,
41- 'violation ' => 'structure differs from doc-en (EN: %s | translation: %s) [blocks EN=%d translation=%d] ' ,
42- 'summary ' => "checked=%d divergent=%d \n" ,
43- ];
44-
4538$ argv = new ArgvParser ( $ argv );
4639$ argv ->consume ( position: 0 ); // script name
4740$ help = $ argv ->consume ( equals: "--help " ) ?? $ argv ->consume ( equals: "-h " );
4841$ lang = $ argv ->consume ( prefix: "--lang= " );
49- $ msgFile = $ argv ->consume ( prefix: "--messages= " );
5042$ github = $ argv ->consume ( equals: "--github " );
5143$ files = [];
5244foreach ( $ argv ->residual () as $ arg )
5951
6052if ( $ help !== null )
6153{
62- fwrite ( STDERR , "Usage: check-structure.php [--lang=xx] [--messages=file] [-- github] [files...] \n\n" );
54+ fwrite ( STDERR , "Usage: check-structure.php [--lang=xx] [--github] [files...] \n\n" );
6355 fwrite ( STDERR , "Reads file names from the command line, or from standard input when none \n" );
6456 fwrite ( STDERR , "are given. Paths are relative to the translation directory. \n\n" );
6557 fwrite ( STDERR , "See https://github.com/php/doc-base/tree/master/scripts/translation#readme for more info. \n" );
6658 exit ( 0 );
6759}
6860
6961$ lang = requireLang ( $ lang );
70- $ messages = loadMessages ( $ msgFile );
7162$ files = $ files === [] ? readPathsFromStdin () : $ files ;
7263
7364// -- Setup -----------------------------------------------------------------
@@ -91,33 +82,6 @@ function requireLang( ?string $lang ) : string
9182 return trim ( file_get_contents ( $ file ) );
9283}
9384
94- /**
95- * Message catalog. A translation may hand its own file over --messages=, so
96- * that contributors read alerts in their language. The file returns an array
97- * with any of the DEFAULT_MESSAGES keys; missing keys fall back to English.
98- */
99- function loadMessages ( ?string $ filename ) : array
100- {
101- if ( $ filename === null || $ filename === '' )
102- return DEFAULT_MESSAGES ;
103-
104- if ( ! is_file ( $ filename ) )
105- {
106- fwrite ( STDERR , "Message file not found: $ filename \n" );
107- exit ( 1 );
108- }
109-
110- $ messages = require $ filename ;
111-
112- if ( ! is_array ( $ messages ) )
113- {
114- fwrite ( STDERR , "Message file must return an array: $ filename \n" );
115- exit ( 1 );
116- }
117-
118- return array_merge ( DEFAULT_MESSAGES , $ messages );
119- }
120-
12185/**
12286 * File names read from standard input, one per line, .xml only. This is how a
12387 * CI job hands over the list of files a pull request touches.
@@ -189,12 +153,12 @@ function collectSkeleton( DOMElement $element , string $depth , array & $skeleto
189153 * Undeclared entities are left to XmlUtil::loadText(), which recovers from
190154 * them; both sides go through the same loader, so the treatment is symmetric.
191155 */
192- function buildSkeleton ( string $ xml , array $ messages ) : array
156+ function buildSkeleton ( string $ xml ) : array
193157{
194158 $ document = XmlUtil::loadText ( $ xml );
195159
196160 if ( $ document ->documentElement === null )
197- return [ $ messages [ ' invalid ' ] ];
161+ return [ ' <<INVALID>> ' ];
198162
199163 $ skeleton = [];
200164 collectSkeleton ( $ document ->documentElement , '' , $ skeleton );
@@ -226,7 +190,7 @@ function docEnFileAtRevision( string $hash , string $file ) : ?string
226190 * First position where two skeletons differ, as [ enLine , targetLine ], or
227191 * null when they are identical. A missing line is reported as "(none)".
228192 */
229- function firstDivergence ( array $ enSkeleton , array $ targetSkeleton , array $ messages ) : ?array
193+ function firstDivergence ( array $ enSkeleton , array $ targetSkeleton ) : ?array
230194{
231195 $ length = max ( count ( $ enSkeleton ) , count ( $ targetSkeleton ) );
232196
@@ -237,8 +201,8 @@ function firstDivergence( array $enSkeleton , array $targetSkeleton , array $mes
237201
238202 if ( $ enLine !== $ targetLine )
239203 return [
240- trim ( $ enSkeleton [ $ i ] ?? $ messages [ ' none ' ] ) ,
241- trim ( $ targetSkeleton [ $ i ] ?? $ messages [ ' none ' ] ) ,
204+ trim ( $ enSkeleton [ $ i ] ?? ' ( none) ' ) ,
205+ trim ( $ targetSkeleton [ $ i ] ?? ' ( none) ' ) ,
242206 ];
243207 }
244208
@@ -281,9 +245,9 @@ function firstDivergence( array $enSkeleton , array $targetSkeleton , array $mes
281245
282246 $ checked ++;
283247
284- $ enSkeleton = buildSkeleton ( $ enXml , $ messages );
285- $ targetSkeleton = buildSkeleton ( $ targetXml , $ messages );
286- $ divergence = firstDivergence ( $ enSkeleton , $ targetSkeleton , $ messages );
248+ $ enSkeleton = buildSkeleton ( $ enXml );
249+ $ targetSkeleton = buildSkeleton ( $ targetXml );
250+ $ divergence = firstDivergence ( $ enSkeleton , $ targetSkeleton );
287251
288252 if ( $ divergence === null )
289253 continue ;
@@ -298,7 +262,10 @@ function firstDivergence( array $enSkeleton , array $targetSkeleton , array $mes
298262
299263foreach ( $ violations as [ $ file , $ enLine , $ targetLine , $ enCount , $ targetCount ] )
300264{
301- $ message = sprintf ( $ messages [ 'violation ' ] , $ enLine , $ targetLine , $ enCount , $ targetCount );
265+ $ message = sprintf (
266+ 'structure differs from doc-en (EN: %s | translation: %s) [blocks EN=%d translation=%d] ' ,
267+ $ enLine , $ targetLine , $ enCount , $ targetCount
268+ );
302269
303270 // Under GitHub Actions the path must be relative to the repository being
304271 // annotated, so that the alert lands on the right file of the pull request.
@@ -309,6 +276,6 @@ function firstDivergence( array $enSkeleton , array $targetSkeleton , array $mes
309276 printf ( "%s/%s: %s \n" , $ lang , $ file , $ message );
310277}
311278
312- fprintf ( STDERR , $ messages [ ' summary ' ] , $ checked , count ( $ violations ) );
279+ fprintf ( STDERR , " checked=%d divergent=%d \n" , $ checked , count ( $ violations ) );
313280
314281exit ( $ violations === [] ? 0 : 1 );
0 commit comments