Skip to content

Commit d2fee0a

Browse files
author
André L F S Bacci
committed
Detect duplicated entity names on first language
1 parent 9610bb8 commit d2fee0a

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

scripts/entities.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,21 @@
9898
$filename = Entities::rotateOutputFile(); // idempotent
9999

100100
$langs = [];
101-
$normal = true; // Normal configure.php mode
101+
$normal = true;
102+
$debug = false;
102103

103104
for( $idx = 1 ; $idx < count( $argv ) ; $idx++ )
104105
if ( $argv[$idx] == "--debug" )
105106
$normal = false;
106107
else
107108
$langs[] = $argv[$idx];
108-
109109
$debug = ! $normal;
110110

111111
if ( $normal )
112112
print "Creating .entities.ent...";
113113
else
114114
print "Creating .entities.ent in debug mode.\n";
115+
$debug = ! $normal;
115116

116117
loadEnt( __DIR__ . "/../global.ent" , global: true , warnMissing: true );
117118
foreach( $langs as $lang )
@@ -120,6 +121,7 @@
120121
loadEnt( __DIR__ . "/../../$lang/manual.ent" , translate: true , warnMissing: true );
121122
loadEnt( __DIR__ . "/../../$lang/remove.ent" , remove: true );
122123
loadDir( $langs , $lang );
124+
Entities::$debugUnique = false;
123125
}
124126

125127
Entities::writeOutputFile();
@@ -132,6 +134,8 @@
132134
echo ", " , Entities::$countReplacedGlobal , " global replaced";
133135
if ( Entities::$countReplacedRemove > 0 )
134136
echo ", " , Entities::$countReplacedRemove , " remove replaced";
137+
if ( Entities::$countDuplicated > 0 )
138+
echo ", " , Entities::$countDuplicated , " duplicated (first language)";
135139
echo ".\n";
136140

137141
exit;
@@ -146,20 +150,24 @@ public function __construct(
146150

147151
class Entities
148152
{
149-
public static int $countUnstranslated = 0;
150-
public static int $countReplacedGlobal = 0;
151-
public static int $countReplacedRemove = 0;
152-
public static int $countTotalGenerated = 0;
153-
154153
private static string $filename = __DIR__ . "/../temp/entities.ent"; // idempotent
155154

156155
private static array $entities = []; // All entities, bi duplications
157156
private static array $global = []; // Entities expected not replaced
158157
private static array $replace = []; // Entities expected replaced / translated
159158
private static array $remove = []; // Entities expected not replaced and not used
159+
private static array $unique = []; // For detecting duplicated global+en entities
160160
private static array $count = []; // Name / Count
161161
private static array $slow = []; // External entities, slow, uncontrolled file overwrites
162162

163+
public static bool $debugUnique = true; // Start on unique mode, disable on second language
164+
165+
public static int $countUnstranslated = 0;
166+
public static int $countReplacedGlobal = 0;
167+
public static int $countReplacedRemove = 0;
168+
public static int $countTotalGenerated = 0;
169+
public static int $countDuplicated = 0;
170+
163171
static function put( string $path , string $name , string $text , bool $global = false , bool $replace = false , bool $remove = false )
164172
{
165173
$entity = new EntityData( $path , $name , $text );
@@ -174,10 +182,22 @@ static function put( string $path , string $name , string $text , bool $global =
174182
if ( $remove )
175183
Entities::$remove[ $name ] = $name;
176184

177-
if ( ! isset( Entities::$count[$name] ) )
185+
if ( ! isset( Entities::$count[ $name ] ) )
178186
Entities::$count[$name] = 1;
179187
else
180188
Entities::$count[$name]++;
189+
190+
if ( Entities::$debugUnique )
191+
{
192+
if ( isset( Entities::$unique[ $name ] ) )
193+
{
194+
Entities::$countDuplicated++;
195+
if ( Entities::$countDuplicated == 1 )
196+
fwrite( STDERR , "\n" );
197+
fwrite( STDERR , "\n Duplicated entity: $name\n" );
198+
}
199+
Entities::$unique[ $name ] = $entity;
200+
}
181201
}
182202

183203
static function slow( string $path )

0 commit comments

Comments
 (0)