[DOC-CVS] [doc-base] master: Add --lang and file listing to sync XML tools (#275)

[email protected] (Louis-Arnaud via GitHub)
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: Louis-Arnaud (lacatoire)
Committer: GitHub (web-flow)
Pusher: alfsb
Date: 2026-02-12T17:22:52-03:00

Commit: https://github.com/php/doc-base/commit/25287dfd9ffe587ea535054e968b0441304bed71
Raw diff: https://github.com/php/doc-base/commit/25287dfd9ffe587ea535054e968b0441304bed71.diff

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.

Changed paths:
  M  scripts/translation/libqa/SyncFileList.php
  M  scripts/translation/qaxml-attributes.php
  M  scripts/translation/qaxml-entities.php
  M  scripts/translation/qaxml-pi.php
  M  scripts/translation/qaxml-revtag.php
  M  scripts/translation/qaxml-tags.php
  M  scripts/translation/qaxml-ws.php


Diff:

diff --git a/scripts/translation/libqa/SyncFileList.php b/scripts/translation/libqa/SyncFileList.php
index 2d06c3a349..35caee99f2 100644
--- a/scripts/translation/libqa/SyncFileList.php
+++ b/scripts/translation/libqa/SyncFileList.php
@@ -21,16 +21,49 @@
 
 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 @@ static function load()
             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;
diff --git a/scripts/translation/qaxml-attributes.php b/scripts/translation/qaxml-attributes.php
index a2a7de22d4..df6eb0e75c 100644
--- a/scripts/translation/qaxml-attributes.php
+++ b/scripts/translation/qaxml-attributes.php
@@ -22,10 +22,18 @@
 $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;
diff --git a/scripts/translation/qaxml-entities.php b/scripts/translation/qaxml-entities.php
index 1bb7c363be..cfe473bbe7 100644
--- a/scripts/translation/qaxml-entities.php
+++ b/scripts/translation/qaxml-entities.php
@@ -22,19 +22,26 @@
 $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 )
 {
diff --git a/scripts/translation/qaxml-pi.php b/scripts/translation/qaxml-pi.php
index 1590631e81..e9b1acab23 100644
--- a/scripts/translation/qaxml-pi.php
+++ b/scripts/translation/qaxml-pi.php
@@ -21,9 +21,17 @@
 
 $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 )
 {
diff --git a/scripts/translation/qaxml-revtag.php b/scripts/translation/qaxml-revtag.php
index 850b8cbd72..7d8862ed61 100644
--- a/scripts/translation/qaxml-revtag.php
+++ b/scripts/translation/qaxml-revtag.php
@@ -23,9 +23,17 @@
 $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 )
 {
diff --git a/scripts/translation/qaxml-tags.php b/scripts/translation/qaxml-tags.php
index fc9514c36d..910c091301 100644
--- a/scripts/translation/qaxml-tags.php
+++ b/scripts/translation/qaxml-tags.php
@@ -23,13 +23,20 @@
 $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 )
 {
diff --git a/scripts/translation/qaxml-ws.php b/scripts/translation/qaxml-ws.php
index 2a8db8238f..a44fd99a8c 100644
--- a/scripts/translation/qaxml-ws.php
+++ b/scripts/translation/qaxml-ws.php
@@ -22,9 +22,17 @@
 
 $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 )
 {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.