9898$ filename = Entities::rotateOutputFile (); // idempotent
9999
100100$ langs = [];
101- $ normal = true ; // Normal configure.php mode
101+ $ normal = true ;
102+ $ debug = false ;
102103
103104for ( $ 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
111111if ( $ normal )
112112 print "Creating .entities.ent... " ;
113113else
114114 print "Creating .entities.ent in debug mode. \n" ;
115+ $ debug = ! $ normal ;
115116
116117loadEnt ( __DIR__ . "/../global.ent " , global: true , warnMissing: true );
117118foreach ( $ langs as $ lang )
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
125127Entities::writeOutputFile ();
132134 echo ", " , Entities::$ countReplacedGlobal , " global replaced " ;
133135if ( Entities::$ countReplacedRemove > 0 )
134136 echo ", " , Entities::$ countReplacedRemove , " remove replaced " ;
137+ if ( Entities::$ countDuplicated > 0 )
138+ echo ", " , Entities::$ countDuplicated , " duplicated (first language) " ;
135139echo ". \n" ;
136140
137141exit ;
@@ -146,20 +150,24 @@ public function __construct(
146150
147151class 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