Skip to content

Commit 25287df

Browse files
authored
Add --lang and file listing to sync XML tools (#275)
* Add --lang= parameter and simple file listing to sync XML tools Allow all qaxml-*.php scripts to accept --lang=XX to specify the target language directly, without requiring temp/lang from configure.php. Also accept file paths as positional arguments for checking specific files instead of the full translation tree. Existing behavior without parameters is preserved. Relates to #199. * Rename $files to $filterFiles and warn on missing source files Address review feedback: rename parameter for clarity and add STDERR warning when a command-line file is not found in sourceDir.
1 parent 845f7c4 commit 25287df

File tree

7 files changed

+100
-24
lines changed

7 files changed

+100
-24
lines changed

scripts/translation/libqa/SyncFileList.php

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,62 @@
2121

2222
class SyncFileList
2323
{
24-
static function load()
24+
static function load( ?string $lang = null , array $filterFiles = [] )
2525
{
26-
$file = __DIR__ . "/../../../temp/lang";
27-
if ( ! file_exists( $file ) )
26+
if ( $lang === null )
2827
{
29-
fwrite( STDERR , "Language file not found, run 'doc-base/configure.php'.\n" );
30-
exit();
28+
$file = __DIR__ . "/../../../temp/lang";
29+
if ( ! file_exists( $file ) )
30+
{
31+
fwrite( STDERR , "Language not found, run 'doc-base/configure.php' or use '--lang='.\n" );
32+
exit();
33+
}
34+
$lang = trim( file_get_contents( $file ) );
35+
}
36+
37+
$sourceDir = 'en';
38+
$targetDir = $lang;
39+
40+
if ( count( $filterFiles ) > 0 )
41+
{
42+
$ret = [];
43+
44+
foreach ( $filterFiles as $file )
45+
{
46+
if ( ! file_exists( "$sourceDir/$file" ) )
47+
{
48+
fwrite( STDERR , "File not found in source: $sourceDir/$file\n" );
49+
continue;
50+
}
51+
if ( ! file_exists( "$targetDir/$file" ) )
52+
continue;
53+
54+
$item = new SyncFileItem();
55+
$item->sourceDir = $sourceDir;
56+
$item->targetDir = $targetDir;
57+
$item->file = $file;
58+
$ret[] = $item;
59+
}
60+
61+
if ( $ret === [] )
62+
throw new Exception( "No matching files found." );
63+
64+
return $ret;
3165
}
3266

33-
$lang = trim( file_get_contents( $file ) );
3467
$cacheFilename = __DIR__ . "/../../../temp/qaxml.files.$lang";
3568

3669
if ( file_exists( $cacheFilename ) )
3770
{
3871
return unserialize( gzdecode( file_get_contents( $cacheFilename ) ) );
3972
}
4073

41-
$sourceDir = 'en';
42-
$targetDir = $lang;
43-
4474
require_once __DIR__ . '/../lib/all.php';
4575

46-
$files = new RevcheckFileList( $sourceDir );
76+
$revFiles = new RevcheckFileList( $sourceDir );
4777
$ret = [];
4878

49-
foreach( $files->iterator() as $file )
79+
foreach( $revFiles->iterator() as $file )
5080
{
5181
if ( ! file_exists( "$targetDir/{$file->file}" ) )
5282
continue;

scripts/translation/qaxml-attributes.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@
2222
$argv = new ArgvParser( $argv );
2323
$ignore = new OutputIgnore( $argv ); // may exit.
2424
$urgent = $argv->consume( "--urgent" ) != null;
25-
26-
$list = SyncFileList::load();
25+
$lang = $argv->consume( prefix: "--lang=" );
26+
$files = [];
27+
foreach ( $argv->residual() as $arg )
28+
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
29+
{
30+
$files[] = $arg;
31+
$argv->use( $arg );
32+
}
2733
$argv->complete();
2834

35+
$list = SyncFileList::load( $lang , $files );
36+
2937
foreach ( $list as $file )
3038
{
3139
$source = $file->sourceDir . '/' . $file->file;

scripts/translation/qaxml-entities.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,26 @@
2222
$argv = new ArgvParser( $argv );
2323
$ignore = new OutputIgnore( $argv ); // may exit.
2424
$urgent = $argv->consume( "--urgent" ) != null;
25+
$lang = $argv->consume( prefix: "--lang=" );
2526

26-
$ents = [];
27-
foreach( $argv->residual() as $ent )
27+
$ents = [];
28+
$files = [];
29+
foreach( $argv->residual() as $arg )
2830
{
29-
if ( strlen( $ent ) > 2 && $ent[0] == '-' && $ent[1] != '-' )
31+
if ( strlen( $arg ) > 2 && $arg[0] == '-' && $arg[1] != '-' )
3032
{
31-
$ents[] = '&' . substr( $ent , 1) . ';';
32-
$argv->use( $ent );
33+
$ents[] = '&' . substr( $arg , 1) . ';';
34+
$argv->use( $arg );
35+
}
36+
elseif ( strlen( $arg ) > 0 && $arg[0] != '-' )
37+
{
38+
$files[] = $arg;
39+
$argv->use( $arg );
3340
}
3441
}
3542
$argv->complete();
3643

37-
$list = SyncFileList::load();
44+
$list = SyncFileList::load( $lang , $files );
3845

3946
foreach ( $list as $file )
4047
{

scripts/translation/qaxml-pi.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@
2121

2222
$argv = new ArgvParser( $argv );
2323
$ignore = new OutputIgnore( $argv ); // may exit.
24+
$lang = $argv->consume( prefix: "--lang=" );
25+
$files = [];
26+
foreach ( $argv->residual() as $arg )
27+
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
28+
{
29+
$files[] = $arg;
30+
$argv->use( $arg );
31+
}
2432
$argv->complete();
2533

26-
$list = SyncFileList::load();
34+
$list = SyncFileList::load( $lang , $files );
2735

2836
foreach ( $list as $file )
2937
{

scripts/translation/qaxml-revtag.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@
2323
$argv = new ArgvParser( $argv );
2424
$ignore = new OutputIgnore( $argv ); // may exit.
2525
$ignore->appendIgnoreCommands = false;
26+
$lang = $argv->consume( prefix: "--lang=" );
27+
$files = [];
28+
foreach ( $argv->residual() as $arg )
29+
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
30+
{
31+
$files[] = $arg;
32+
$argv->use( $arg );
33+
}
2634
$argv->complete();
2735

28-
$list = SyncFileList::load();
36+
$list = SyncFileList::load( $lang , $files );
2937

3038
foreach ( $list as $file )
3139
{

scripts/translation/qaxml-tags.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@
2323
$ignore = new OutputIgnore( $argv ); // may exit.
2424
$detail = $argv->consume( "--detail" ) != null;
2525
$tags = explode( ',' , $argv->consume( prefix: "--content=" ) ?? "" );
26-
26+
$lang = $argv->consume( prefix: "--lang=" );
27+
$files = [];
28+
foreach ( $argv->residual() as $arg )
29+
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
30+
{
31+
$files[] = $arg;
32+
$argv->use( $arg );
33+
}
2734
$argv->complete();
2835

2936
if ( count( $tags ) == 1 && $tags[0] == "" )
3037
$tags = [];
3138

32-
$list = SyncFileList::load();
39+
$list = SyncFileList::load( $lang , $files );
3340

3441
foreach ( $list as $file )
3542
{

scripts/translation/qaxml-ws.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@
2222

2323
$argv = new ArgvParser( $argv );
2424
$ignore = new OutputIgnore( $argv ); // may exit.
25+
$lang = $argv->consume( prefix: "--lang=" );
26+
$files = [];
27+
foreach ( $argv->residual() as $arg )
28+
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
29+
{
30+
$files[] = $arg;
31+
$argv->use( $arg );
32+
}
2533
$argv->complete();
2634

27-
$list = SyncFileList::load();
35+
$list = SyncFileList::load( $lang , $files );
2836

2937
foreach ( $list as $file )
3038
{

0 commit comments

Comments
 (0)