Skip to content

Commit 00d86bc

Browse files
committed
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.
1 parent 845f7c4 commit 00d86bc

File tree

7 files changed

+95
-24
lines changed

7 files changed

+95
-24
lines changed

scripts/translation/libqa/SyncFileList.php

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

2222
class SyncFileList
2323
{
24-
static function load()
24+
static function load( ?string $lang = null , array $files = [] )
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( $files ) > 0 )
41+
{
42+
$ret = [];
43+
44+
foreach ( $files as $file )
45+
{
46+
if ( ! file_exists( "$targetDir/$file" ) )
47+
continue;
48+
49+
$item = new SyncFileItem();
50+
$item->sourceDir = $sourceDir;
51+
$item->targetDir = $targetDir;
52+
$item->file = $file;
53+
$ret[] = $item;
54+
}
55+
56+
if ( $ret === [] )
57+
throw new Exception( "No matching files found." );
58+
59+
return $ret;
3160
}
3261

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

3664
if ( file_exists( $cacheFilename ) )
3765
{
3866
return unserialize( gzdecode( file_get_contents( $cacheFilename ) ) );
3967
}
4068

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

46-
$files = new RevcheckFileList( $sourceDir );
71+
$revFiles = new RevcheckFileList( $sourceDir );
4772
$ret = [];
4873

49-
foreach( $files->iterator() as $file )
74+
foreach( $revFiles->iterator() as $file )
5075
{
5176
if ( ! file_exists( "$targetDir/{$file->file}" ) )
5277
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)