mirror of
https://github.com/php/doc-base.git
synced 2026-03-23 23:02:13 +01:00
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.
This commit is contained in:
@@ -21,16 +21,49 @@ require_once __DIR__ . '/all.php';
|
||||
|
||||
class SyncFileList
|
||||
{
|
||||
static function load()
|
||||
static function load( ?string $lang = null , array $filterFiles = [] )
|
||||
{
|
||||
$file = __DIR__ . "/../../../temp/lang";
|
||||
if ( ! file_exists( $file ) )
|
||||
if ( $lang === null )
|
||||
{
|
||||
fwrite( STDERR , "Language file not found, run 'doc-base/configure.php'.\n" );
|
||||
exit();
|
||||
$file = __DIR__ . "/../../../temp/lang";
|
||||
if ( ! file_exists( $file ) )
|
||||
{
|
||||
fwrite( STDERR , "Language not found, run 'doc-base/configure.php' or use '--lang='.\n" );
|
||||
exit();
|
||||
}
|
||||
$lang = trim( file_get_contents( $file ) );
|
||||
}
|
||||
|
||||
$sourceDir = 'en';
|
||||
$targetDir = $lang;
|
||||
|
||||
if ( count( $filterFiles ) > 0 )
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
foreach ( $filterFiles as $file )
|
||||
{
|
||||
if ( ! file_exists( "$sourceDir/$file" ) )
|
||||
{
|
||||
fwrite( STDERR , "File not found in source: $sourceDir/$file\n" );
|
||||
continue;
|
||||
}
|
||||
if ( ! file_exists( "$targetDir/$file" ) )
|
||||
continue;
|
||||
|
||||
$item = new SyncFileItem();
|
||||
$item->sourceDir = $sourceDir;
|
||||
$item->targetDir = $targetDir;
|
||||
$item->file = $file;
|
||||
$ret[] = $item;
|
||||
}
|
||||
|
||||
if ( $ret === [] )
|
||||
throw new Exception( "No matching files found." );
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$lang = trim( file_get_contents( $file ) );
|
||||
$cacheFilename = __DIR__ . "/../../../temp/qaxml.files.$lang";
|
||||
|
||||
if ( file_exists( $cacheFilename ) )
|
||||
@@ -38,15 +71,12 @@ class SyncFileList
|
||||
return unserialize( gzdecode( file_get_contents( $cacheFilename ) ) );
|
||||
}
|
||||
|
||||
$sourceDir = 'en';
|
||||
$targetDir = $lang;
|
||||
|
||||
require_once __DIR__ . '/../lib/all.php';
|
||||
|
||||
$files = new RevcheckFileList( $sourceDir );
|
||||
$revFiles = new RevcheckFileList( $sourceDir );
|
||||
$ret = [];
|
||||
|
||||
foreach( $files->iterator() as $file )
|
||||
foreach( $revFiles->iterator() as $file )
|
||||
{
|
||||
if ( ! file_exists( "$targetDir/{$file->file}" ) )
|
||||
continue;
|
||||
|
||||
@@ -22,10 +22,18 @@ require_once __DIR__ . '/libqa/all.php';
|
||||
$argv = new ArgvParser( $argv );
|
||||
$ignore = new OutputIgnore( $argv ); // may exit.
|
||||
$urgent = $argv->consume( "--urgent" ) != null;
|
||||
|
||||
$list = SyncFileList::load();
|
||||
$lang = $argv->consume( prefix: "--lang=" );
|
||||
$files = [];
|
||||
foreach ( $argv->residual() as $arg )
|
||||
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
|
||||
{
|
||||
$files[] = $arg;
|
||||
$argv->use( $arg );
|
||||
}
|
||||
$argv->complete();
|
||||
|
||||
$list = SyncFileList::load( $lang , $files );
|
||||
|
||||
foreach ( $list as $file )
|
||||
{
|
||||
$source = $file->sourceDir . '/' . $file->file;
|
||||
|
||||
@@ -22,19 +22,26 @@ require_once __DIR__ . '/libqa/all.php';
|
||||
$argv = new ArgvParser( $argv );
|
||||
$ignore = new OutputIgnore( $argv ); // may exit.
|
||||
$urgent = $argv->consume( "--urgent" ) != null;
|
||||
$lang = $argv->consume( prefix: "--lang=" );
|
||||
|
||||
$ents = [];
|
||||
foreach( $argv->residual() as $ent )
|
||||
$ents = [];
|
||||
$files = [];
|
||||
foreach( $argv->residual() as $arg )
|
||||
{
|
||||
if ( strlen( $ent ) > 2 && $ent[0] == '-' && $ent[1] != '-' )
|
||||
if ( strlen( $arg ) > 2 && $arg[0] == '-' && $arg[1] != '-' )
|
||||
{
|
||||
$ents[] = '&' . substr( $ent , 1) . ';';
|
||||
$argv->use( $ent );
|
||||
$ents[] = '&' . substr( $arg , 1) . ';';
|
||||
$argv->use( $arg );
|
||||
}
|
||||
elseif ( strlen( $arg ) > 0 && $arg[0] != '-' )
|
||||
{
|
||||
$files[] = $arg;
|
||||
$argv->use( $arg );
|
||||
}
|
||||
}
|
||||
$argv->complete();
|
||||
|
||||
$list = SyncFileList::load();
|
||||
$list = SyncFileList::load( $lang , $files );
|
||||
|
||||
foreach ( $list as $file )
|
||||
{
|
||||
|
||||
@@ -21,9 +21,17 @@ require_once __DIR__ . '/libqa/all.php';
|
||||
|
||||
$argv = new ArgvParser( $argv );
|
||||
$ignore = new OutputIgnore( $argv ); // may exit.
|
||||
$lang = $argv->consume( prefix: "--lang=" );
|
||||
$files = [];
|
||||
foreach ( $argv->residual() as $arg )
|
||||
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
|
||||
{
|
||||
$files[] = $arg;
|
||||
$argv->use( $arg );
|
||||
}
|
||||
$argv->complete();
|
||||
|
||||
$list = SyncFileList::load();
|
||||
$list = SyncFileList::load( $lang , $files );
|
||||
|
||||
foreach ( $list as $file )
|
||||
{
|
||||
|
||||
@@ -23,9 +23,17 @@ require_once __DIR__ . '/lib/RevtagParser.php';
|
||||
$argv = new ArgvParser( $argv );
|
||||
$ignore = new OutputIgnore( $argv ); // may exit.
|
||||
$ignore->appendIgnoreCommands = false;
|
||||
$lang = $argv->consume( prefix: "--lang=" );
|
||||
$files = [];
|
||||
foreach ( $argv->residual() as $arg )
|
||||
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
|
||||
{
|
||||
$files[] = $arg;
|
||||
$argv->use( $arg );
|
||||
}
|
||||
$argv->complete();
|
||||
|
||||
$list = SyncFileList::load();
|
||||
$list = SyncFileList::load( $lang , $files );
|
||||
|
||||
foreach ( $list as $file )
|
||||
{
|
||||
|
||||
@@ -23,13 +23,20 @@ $argv = new ArgvParser( $argv );
|
||||
$ignore = new OutputIgnore( $argv ); // may exit.
|
||||
$detail = $argv->consume( "--detail" ) != null;
|
||||
$tags = explode( ',' , $argv->consume( prefix: "--content=" ) ?? "" );
|
||||
|
||||
$lang = $argv->consume( prefix: "--lang=" );
|
||||
$files = [];
|
||||
foreach ( $argv->residual() as $arg )
|
||||
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
|
||||
{
|
||||
$files[] = $arg;
|
||||
$argv->use( $arg );
|
||||
}
|
||||
$argv->complete();
|
||||
|
||||
if ( count( $tags ) == 1 && $tags[0] == "" )
|
||||
$tags = [];
|
||||
|
||||
$list = SyncFileList::load();
|
||||
$list = SyncFileList::load( $lang , $files );
|
||||
|
||||
foreach ( $list as $file )
|
||||
{
|
||||
|
||||
@@ -22,9 +22,17 @@ require_once __DIR__ . '/libqa/all.php';
|
||||
|
||||
$argv = new ArgvParser( $argv );
|
||||
$ignore = new OutputIgnore( $argv ); // may exit.
|
||||
$lang = $argv->consume( prefix: "--lang=" );
|
||||
$files = [];
|
||||
foreach ( $argv->residual() as $arg )
|
||||
if ( strlen( $arg ) > 0 && $arg[0] != '-' )
|
||||
{
|
||||
$files[] = $arg;
|
||||
$argv->use( $arg );
|
||||
}
|
||||
$argv->complete();
|
||||
|
||||
$list = SyncFileList::load();
|
||||
$list = SyncFileList::load( $lang , $files );
|
||||
|
||||
foreach ( $list as $file )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user