alter Satz → neuer Satz */ public const REPLACEMENTS = [ 'Mit deutscher Vertragssicherheit und einem eingespielten Herstellernetzwerk.' => 'Mit einem zentralen deutschen Vertragspartner und einem eingespielten Herstellernetzwerk.', 'With German contractual reliability and an established manufacturer network.' => 'With a single German contract partner and an established manufacturer network.', ]; public function run(): void { $row = CmsContent::query()->where('group', 'home')->where('key', 'audience_switch')->first(); if (! $row) { $this->command?->info('Projekttext: Sektion home/audience_switch nicht im CMS – die Lang-Datei gilt.'); return; } $value = $row->getTranslations('value'); $count = 0; $value = $this->replaceDeep($value, $count); if ($count === 0) { $this->command?->info('Projekttext: bereits aktuell, nichts geändert.'); return; } $row->value = $value; $row->save(); app(CmsContentService::class)->clearCache('home'); $this->command?->info("Projekttext ersetzt ({$count} Stelle(n))."); } /** * @param array $data * @return array */ private function replaceDeep(array $data, int &$count): array { foreach ($data as $key => $item) { if (is_array($item)) { $data[$key] = $this->replaceDeep($item, $count); continue; } if (! is_string($item)) { continue; } $replaced = strtr($item, self::REPLACEMENTS); if ($replaced !== $item) { $data[$key] = $replaced; $count++; } } return $data; } }