Skip to content

Commit c63809f

Browse files
authored
Command line tool for XML sync testing between languages: entities (#219)
1 parent 181ecbe commit c63809f

File tree

5 files changed

+75
-10
lines changed

5 files changed

+75
-10
lines changed

scripts/translation/libqa/OutputBuffer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function addDiff( string $text , int $sourceCount , int $targetCount )
6767

6868
public function addFooter( string $text )
6969
{
70-
$this->footer[] = $text;
70+
// $this->footer[] = $text;
7171
}
7272

7373
public function addLine()

scripts/translation/libqa/SyncFileList.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static function load()
3131
}
3232

3333
$lang = trim( file_get_contents( $file ) );
34-
$cache = __DIR__ . "/../../../temp/$lang.oklist";
34+
$cache = __DIR__ . "/../../../temp/qaxml.files.$lang";
3535

3636
if ( file_exists( $cache ) )
3737
{
@@ -47,7 +47,12 @@ static function load()
4747

4848
foreach( $revdata->fileDetail as $file )
4949
{
50-
if ( $file->status != RevcheckStatus::TranslatedOk )
50+
$source = "{$revcheck->sourceDir}/{$file->path}/{$file->name}";
51+
$target = "{$revcheck->targetDir}/{$file->path}/{$file->name}";
52+
53+
if ( ! file_exists( $source ) )
54+
continue;
55+
if ( ! file_exists( $target ) )
5156
continue;
5257

5358
$item = new SyncFileItem();
@@ -57,6 +62,9 @@ static function load()
5762
$list[] = $item;
5863
}
5964

65+
if ( count( $list ) == 0 )
66+
throw new Exception( "No files found. Called from wrong directory?" );
67+
6068
$contents = gzencode( serialize( $list ) );
6169
file_put_contents( $cache , $contents );
6270

scripts/translation/libqa/XmlFrag.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ static function loadXmlFragmentFile( string $filename )
4444
[ $doc , $ent , $err ] = XmlFrag::loadXmlFragmentText( $contents , "" );
4545

4646
if ( count( $err ) == 0 )
47-
return [ $doc , $err ];
47+
return [ $doc , $ent , $err ];
4848

4949
$dtd = "<?xml version='1.0' encoding='utf-8'?>\n<!DOCTYPE frag [\n";
5050
foreach ( $ent as $e )
5151
$dtd .= "<!ENTITY $e ''>\n";
5252
$dtd .= "]>\n";
5353

54-
[ $doc , $ent , $err ] = XmlFrag::loadXmlFragmentText( $contents , $dtd );
54+
[ $doc , $ign , $err ] = XmlFrag::loadXmlFragmentText( $contents , $dtd );
5555

56-
return [ $doc , $err ];
56+
return [ $doc , $ent , $err ];
5757
}
5858

5959
static function loadXmlFragmentText( string $contents , string $dtd )

scripts/translation/qaxml-sync-attributes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
$target = $file->targetDir . '/' . $file->file;
2929
$output = new OutputBuffer( "# qaxml.a" , $target , $ignore );
3030

31-
[ $s , $e ] = XmlFrag::loadXmlFragmentFile( $source );
32-
[ $t , $e ] = XmlFrag::loadXmlFragmentFile( $target );
31+
[ $s , $_ , $_ ] = XmlFrag::loadXmlFragmentFile( $source );
32+
[ $t , $_ , $_ ] = XmlFrag::loadXmlFragmentFile( $target );
3333

3434
$s = XmlFrag::listNodes( $s , XML_ELEMENT_NODE );
3535
$t = XmlFrag::listNodes( $t , XML_ELEMENT_NODE );
@@ -43,9 +43,9 @@
4343
$match = array();
4444

4545
foreach( $s as $v )
46-
$match[$v] = array( 0 , 0 );
46+
$match[$v] = [ 0 , 0 ];
4747
foreach( $t as $v )
48-
$match[$v] = array( 0 , 0 );
48+
$match[$v] = [ 0 , 0 ];
4949

5050
foreach( $s as $v )
5151
$match[$v][0] += 1;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php /*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) 1997-2025 The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.01 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| https://www.php.net/license/3_01.txt. |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| [email protected], so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Authors: André L F S Bacci <ae php.net> |
14+
+----------------------------------------------------------------------+
15+
16+
# Description
17+
18+
Compare XML entities usage between two XML leaf/fragment files. */
19+
20+
require_once __DIR__ . '/libqa/all.php';
21+
22+
$ignore = new OutputIgnore( $argv ); // always first, may exit.
23+
$list = SyncFileList::load();
24+
25+
foreach ( $list as $file )
26+
{
27+
$source = $file->sourceDir . '/' . $file->file;
28+
$target = $file->targetDir . '/' . $file->file;
29+
$output = new OutputBuffer( "# qaxml.e" , $target , $ignore );
30+
31+
[ $_ , $s , $_ ] = XmlFrag::loadXmlFragmentFile( $source );
32+
[ $_ , $t , $_ ] = XmlFrag::loadXmlFragmentFile( $target );
33+
34+
if ( implode( "\n" , $s ) == implode( "\n" , $t ) )
35+
continue;
36+
37+
$match = array();
38+
39+
foreach( $s as $v )
40+
$match[$v] = [ 0 , 0 ];
41+
foreach( $t as $v )
42+
$match[$v] = [ 0 , 0 ];
43+
44+
foreach( $s as $v )
45+
$match[$v][0] += 1;
46+
foreach( $t as $v )
47+
$match[$v][1] += 1;
48+
49+
foreach( $match as $k => $v )
50+
{
51+
if ( $v[0] == $v[1] )
52+
continue;
53+
$output->addDiff( $k , $v[0] , $v[1] );
54+
}
55+
56+
$output->print();
57+
}

0 commit comments

Comments
 (0)