Skip to content

Commit 41b6057

Browse files
authored
XML Entity by example (doc-base) (#307)
Final touchs for grouped XML Entities on manual.
1 parent cc97f51 commit 41b6057

1 file changed

Lines changed: 54 additions & 39 deletions

File tree

scripts/text-entities.php

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
well-balanced texts; and second, this allows normal revision tracking
6262
per file, without requiring weird changes on `revcheck.php`. Note that
6363
is *invalid* to place XML declaration in these fragment files, at least
64-
in files that are invalid XML documents (on multi-node rooted ones).
64+
in files that are invalid XML documents (on text or multi-element roots).
6565
6666
# Grouped XML Entity files
6767
@@ -74,7 +74,7 @@
7474
with XML namespaces used on the manual, so any individual exported entity
7575
has correct and clean XML namespace annotations. These grouped entity
7676
files are tracked normally by revcheck, but are not directly included
77-
in manual.xml.in, as they only participate in general entity loading,
77+
in manual.xml, as they only participate in general entity generation,
7878
described above.
7979
8080
# Checks
@@ -84,14 +84,15 @@
8484
8585
- "yes": these entities are expected to be translated or replaced;
8686
- "no": these entities are expected not be translated or replaced;
87-
- "delete": these entities should be deleted on sight.
87+
- "remove": these entities should be deleted on sight.
8888
89-
The characteristics above are validated at the end of the script. Use the
90-
--debug argument to also list the names of misused entities.
89+
The characteristics above are validated at the end of the script. You
90+
can use an --debug argument to also list the names of misused entities.
9191
92-
The "delete" value exists to make possible deleting entities from
92+
The "remove" value exists to make possible deleting entities from
9393
doc-en while keeping translations building. To achieve this result,
94-
move any recently deleted to a .ent file with translate="delete".
94+
move any recently deleted of doc-en to a entities/.ent file
95+
annotated with translate="remove".
9596
9697
*/
9798

@@ -122,10 +123,9 @@
122123
else
123124
$langs[] = $arg;
124125

126+
print "Running text-entities.php... ";
125127
if ( $debug )
126-
print "Running text-entities.ent in debug mode.\n";
127-
else
128-
print "Running text-entities.ent... ";
128+
print "\n";
129129

130130
foreach( $langs as $lang )
131131
{
@@ -140,13 +140,11 @@
140140
Entities::writeOutputFile();
141141
Entities::checkReplaces( $debug );
142142

143-
echo "done: generated " , Entities::$countTotalGenerated , " entities";
144-
if ( Entities::$countUntranslated > 0 )
145-
echo ", " , Entities::$countUntranslated , " untranslated";
146-
if ( Entities::$countUniqueReplaced > 0 )
147-
echo ", " , Entities::$countUniqueReplaced , " unique replaced";
148-
if ( Entities::$countRemoveReplaced > 0 )
149-
echo ", " , Entities::$countRemoveReplaced , " remove replaced";
143+
echo "done: " , Entities::$countTotalGenerated , " entities";
144+
if ( Entities::$countTransFailures > 0 )
145+
echo ", " , Entities::$countTransFailures , " untranslated";
146+
if ( Entities::$countOtherFailures > 0 )
147+
echo ", " , Entities::$countOtherFailures , " other failures";
150148
echo ".\n";
151149

152150
exit;
@@ -176,10 +174,9 @@ class Entities
176174
private static array $nameCount = []; // Name / Count
177175

178176
public static int $countLanguages = 0; // For translated check
179-
public static int $countUntranslated = 0;
180-
public static int $countUniqueReplaced = 0;
181-
public static int $countRemoveReplaced = 0;
182177
public static int $countTotalGenerated = 0;
178+
public static int $countTransFailures = 0;
179+
public static int $countOtherFailures = 0;
183180

184181
static function put( string $path , string $name , string $text , bool $unique = false , bool $remove = false )
185182
{
@@ -213,50 +210,65 @@ static function writeOutputFile()
213210
static function checkReplaces( bool $debug )
214211
{
215212
Entities::$countTotalGenerated = count( Entities::$merged );
216-
Entities::$countUntranslated = 0;
217-
Entities::$countUniqueReplaced = 0;
218-
Entities::$countRemoveReplaced = 0;
213+
Entities::$countTransFailures = 0;
214+
Entities::$countOtherFailures = 0;
219215

220216
foreach( Entities::$merged as $name => $null )
221217
{
222218
$replaced = Entities::$nameCount[$name] - 1;
223219
$languages = Entities::$countLanguages;
224-
$expectedUnique = in_array( $name , Entities::$unique );
225-
$expectedRemoved = in_array( $name , Entities::$remove );
226-
$expectedTranslated = ! ( $expectedUnique || $expectedRemoved );
220+
$entityUnique = in_array( $name , Entities::$unique );
221+
$entityRemove = in_array( $name , Entities::$remove );
222+
$entityNormal = ! ( $entityUnique || $entityRemove );
227223

228-
if ( $expectedUnique && $replaced != 0 )
224+
if ( $entityUnique && $replaced != 0 )
229225
{
230-
Entities::$countUniqueReplaced++;
226+
Entities::$countOtherFailures++;
231227
if ( $debug )
232-
print " Expected unique, replaced $replaced times: $name\n";
228+
print " Unique entity, redefined $replaced times: $name\n";
233229
}
234230

235-
if ( $expectedRemoved && $replaced != 0 )
231+
if ( $entityRemove && $replaced != 0 )
236232
{
237-
Entities::$countRemoveReplaced++;
233+
Entities::$countOtherFailures++;
238234
if ( $debug )
239-
print " Expected removed, replaced $replaced times: $name\n";
235+
print " Remove entity, redefined $replaced times: $name\n";
240236
}
241237

242-
if ( $expectedTranslated && $replaced != 1 && $languages != 1 )
238+
if ( $entityNormal && $languages == 1 && $replaced != 0 )
243239
{
244-
Entities::$countUntranslated++;
240+
Entities::$countOtherFailures++;
245241
if ( $debug )
246-
print " Expected translated, replaced $replaced times: $name\n";
242+
print " Normal entity, redefined $replaced times: $name\n";
243+
}
244+
245+
if ( $entityNormal && $languages != 1 )
246+
{
247+
if ( $replaced == 0 )
248+
{
249+
Entities::$countTransFailures++;
250+
if ( $debug )
251+
print " Not translated: $name\n";
252+
}
253+
else
254+
{
255+
Entities::$countOtherFailures++;
256+
if ( $debug )
257+
print " Multiple redefined/translated: $name\n";
258+
}
247259
}
248260
}
249261
}
250262
}
251263

252264
function loadDirEntities( string $dir )
253265
{
254-
$dir = realpath( $dir );
255-
if ( $dir === false || ! is_dir( $dir ) )
266+
if ( realpath( $dir ) === false || ! is_dir( $dir ) )
256267
{
257268
if ( PARTIAL_IMPL )
258269
{
259-
print "\n Skiped $lang/entities\n";
270+
global $lang;
271+
print "(skiped $lang/entities) ";
260272
return;
261273
}
262274
else
@@ -266,8 +278,10 @@ function loadDirEntities( string $dir )
266278
}
267279
}
268280

281+
$dir = realpath( $dir );
269282
$files = scandir( $dir );
270283
foreach( $files as $file )
284+
foreach( $files as $file )
271285
{
272286
$path = realpath( "$dir/$file" );
273287

@@ -317,10 +331,11 @@ function loadEntityGroup( string $path )
317331
$value = $dom->documentElement->getAttribute("translate");
318332
switch ( $value )
319333
{
334+
case "yes":
335+
break;
320336
case "no":
321337
$unique = true;
322338
break;
323-
case "delete":
324339
case "remove":
325340
$remove = true;
326341
break;

0 commit comments

Comments
 (0)