@@ -85,21 +85,25 @@ public function processTranslation(TranslationArgs $args): mixed
8585
8686 // Handle top-level entities that implement TranslatableInterface
8787 if ($ entity instanceof TranslatableInterface) {
88- $ tuuid = $ entity ->getTuuid ();
89- $ cacheKey = $ tuuid instanceof Tuuid ? $ tuuid ->getValue ().': ' .$ locale : null ;
88+ $ cacheKey = null ;
89+
90+ $ tuuid = $ entity ->getTuuid ();
91+ if ($ tuuid instanceof Tuuid && !empty ($ tuuid ->getValue ())) {
92+ $ cacheKey = $ tuuid ->getValue ().': ' .$ locale ;
93+ }
9094
9195 // Return cached translation immediately if available
92- if ($ cacheKey && isset ($ this ->translationCache [(string ) $ tuuid ][$ locale ])) {
96+ if (null !== $ cacheKey && isset ($ this ->translationCache [(string ) $ tuuid ][$ locale ])) {
9397 return $ this ->translationCache [(string ) $ tuuid ][$ locale ];
9498 }
9599
96100 // Detect cycles to avoid infinite recursion
97- if ($ cacheKey && isset ($ this ->inProgress [$ cacheKey ])) {
101+ if (null !== $ cacheKey && isset ($ this ->inProgress [$ cacheKey ])) {
98102 return $ entity ;
99103 }
100104
101105 // Mark as in-progress and attempt to warm up existing translations from the database
102- if ($ cacheKey ) {
106+ if (null !== $ cacheKey ) {
103107 $ this ->inProgress [$ cacheKey ] = true ;
104108 // Warmup existing translations from DB
105109 $ this ->warmupTranslations ([$ entity ], $ locale );
@@ -167,21 +171,17 @@ public function processTranslation(TranslationArgs $args): mixed
167171
168172 $ translated = $ handler ->translate ($ args );
169173
170- // POST_TRANSLATE event
171174 if ($ entity instanceof TranslatableInterface && $ translated instanceof TranslatableInterface) {
175+ // POST_TRANSLATE event
172176 $ this ->eventDispatcher ->dispatch (
173177 new TranslateEvent ($ entity , $ locale , $ translated ),
174178 TranslateEvent::POST_TRANSLATE ,
175179 );
176- }
177180
178- // Store translation in cache for reuse
179- if ($ translated instanceof TranslatableInterface && null !== $ translated ->getTuuid ()) {
181+ // Store translation in cache for reuse
180182 $ this ->translationCache [$ translated ->getTuuid ()->getValue ()][$ translated ->getLocale ()] = $ translated ;
181- }
182183
183- // Remove from in-progress set
184- if ($ entity instanceof TranslatableInterface && null !== $ entity ->getTuuid ()) {
184+ // Remove from in-progress set
185185 unset($ this ->inProgress [$ entity ->getTuuid ()->getValue ().': ' .$ locale ]);
186186 }
187187
@@ -238,10 +238,10 @@ private function warmupTranslations(array $entities, string $locale): void
238238 continue ;
239239 }
240240 $ tuuid = $ entity ->getTuuid ();
241- if (null === $ tuuid || isset ($ this ->translationCache [(string ) $ tuuid ][$ locale ])) {
241+ if (isset ($ this ->translationCache [(string ) $ tuuid ][$ locale ])) {
242242 continue ;
243243 }
244- $ byClass [$ entity ::class][] = ( string ) $ tuuid ;
244+ $ byClass [$ entity ::class][] = $ tuuid-> getValue () ;
245245 }
246246
247247 /** @var class-string<TranslatableInterface> $class */
@@ -265,7 +265,7 @@ private function warmupTranslations(array $entities, string $locale): void
265265
266266 foreach ($ translations as $ translation ) {
267267 // @codeCoverageIgnoreStart
268- $ this ->translationCache [( string ) $ translation ->getTuuid ()][$ translation ->getLocale ()] = $ translation ;
268+ $ this ->translationCache [$ translation ->getTuuid ()-> getValue ()][$ translation ->getLocale ()] = $ translation ;
269269 // @codeCoverageIgnoreEnd
270270 }
271271 }
0 commit comments