-
Notifications
You must be signed in to change notification settings - Fork 111
Command line tools for XML sync testing between languages #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the coding style choices are exotic and not even consistent within the same file.
scripts/translation/qaxml-pi.php
Outdated
if ( implode( "\n" , $s ) == implode( "\n" , $t ) ) | ||
continue; | ||
|
||
$sideCount = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$sideCount = array(); | |
$sideCount = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace all array()
usage by []
on new code.
scripts/translation/qaxml-pi.php
Outdated
|
||
function extractPiData( array $list ) | ||
{ | ||
$ret = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ret = array(); | |
$ret = []; |
foreach( $s as $v ) | ||
$sideCount[$v] = [ 0 , 0 ]; | ||
foreach( $t as $v ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this coding style. Usually it would be something like:
foreach( $s as $v ) | |
$sideCount[$v] = [ 0 , 0 ]; | |
foreach( $t as $v ) | |
foreach ($s as $v) | |
$sideCount[$v] = [ 0 , 0 ]; | |
foreach ($t as $v) |
continue; | ||
|
||
print "# qaxml.r: $target\n"; | ||
foreach( $revtag->errors as $error ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
scripts/translation/qaxml-tags.php
Outdated
if ( implode( "\n" , $s ) == implode( "\n" , $t ) ) | ||
continue; | ||
|
||
$sideCount = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$sideCount = array(); | |
$sideCount = []; |
scripts/translation/qaxml-tags.php
Outdated
|
||
function extractTagsInnerText( array $nodes , array $tags ) | ||
{ | ||
$ret = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ret = array(); | |
$ret = []; |
if ( in_array( $tag , $tags ) == false ) | ||
continue; | ||
$text = $node->textContent; | ||
while( true ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly CS which I don't understand.
scripts/translation/qaxml-tags.php
Outdated
|
||
function extractTagsInnerXmls( array $nodes , array $tags ) | ||
{ | ||
$ret = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
} | ||
else | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
} | |
else | |
{ | |
} else { |
scripts/translation/qaxml-tags.php
Outdated
|
||
function collectTagLines( string $file , string $tag ) | ||
{ | ||
$ret = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
scripts/translation/qaxml-pi.php
Outdated
$s = extractPiData( $s ); | ||
$t = extractPiData( $t ); | ||
|
||
if ( implode( "\n" , $s ) == implode( "\n" , $t ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be ===
? I think it would make more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could do the change, but as they are direct returns of identical called function (implode
), the only case where it would compare equals with different types are false like values, basically empty strings and empty arrays. And in this case, they comparing equals is correct, as this is a fast test for "same" result on each side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different ordered elements are what I was thinking. If there's no need for the elements to be in different orders then please use strict comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
scripts/translation/qaxml-pi.php
Outdated
$target = $file->targetDir . '/' . $file->file; | ||
$output = new OutputBuffer( "# qaxml.p" , $target , $ignore ); | ||
|
||
[ $s , $_ , $_ ] = XmlFrag::loadXmlFragmentFile( $source ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you reusing the variable $_
twice? It's just going to overwrite it. And I don't think you are actually using this variable anywhere so why assign it at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function loadXmlFragmentFile()
has 3 returns, but here the code is only interested on first return, so only one is "named" and all other cases are "discarded".
Replacing $_
by _
causes PHP Fatal error: Assignments can only happen to writable values
.
And replacing [ $s , $_ , $_ ]
by $s
causes PHP Fatal error: Uncaught TypeError: XmlFrag::listNodes(): Argument #1 ($node) must be of type DOMNode, array given
.
So I choose a repetitive and uninteresting name, that causes overwrite of variables that need to be positioned, but are unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but you don't have to assign it at all. [$source]
should do fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
$s = XmlFrag::listNodes( $s , XML_PI_NODE ); | ||
$t = XmlFrag::listNodes( $t , XML_PI_NODE ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$s = XmlFrag::listNodes( $s , XML_PI_NODE ); | |
$t = XmlFrag::listNodes( $t , XML_PI_NODE ); | |
$s = XmlFrag::listNodes( $s , XML_PI_NODE ); | |
$t = XmlFrag::listNodes( $t , XML_PI_NODE ); |
$s = XmlFrag::listNodes( $s , XML_PI_NODE ); | |
$t = XmlFrag::listNodes( $t , XML_PI_NODE ); | |
$source = XmlFrag::listNodes( $source , XML_PI_NODE ); | |
$target = XmlFrag::listNodes( $target , XML_PI_NODE ); |
Please don't use single-character variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would need to be also replaced in other parts of code, and will need to be tested. For a future change/rewrite of code.
This PR rewrites the last of old qaxml tools into something that is almost independent of "lib revcheck" code, and adapted to be run in all translations.
After this PR is merged, and new tools announced, the old tools/code removing will be possible. The only dependence renaming are
/lib/RevtagParser.php
, that is a isolated file, andSyncFileList
calling intoRevcheckRun
, that can be replaced with a simple.xml
listing, as the new tools now inspect all files, and does not filter forTranslatedOk
anymore.