Replaced TranslationCompletedListener with AfterTranslateDto across translation-related classes to streamline and enhance the job chaining logic. Added validation to ensure the provided class implements the required interface and included support for additional contextual data in the translation process. This change improves flexibility and simplifies the translation workflow.

This commit is contained in:
2025-01-16 21:04:46 +05:00
parent 31da4eff78
commit e63ded1708
7 changed files with 84 additions and 28 deletions

View File

@@ -10,7 +10,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Str;
use KorElf\TranslateLaravel\Contracts\TranslationCompletedListener;
use KorElf\TranslateLaravel\DTO\AfterTranslateDto;
use KorElf\TranslateLaravel\DTO\ProcessTranslateDto;
use korElf\TranslateLaravel\DTO\RunTranslateDto;
use KorElf\TranslateLaravel\DTO\Translated;
@@ -24,8 +24,8 @@ final class RunTranslate implements ShouldQueue, ShouldBeEncrypted
* Create a new job instance.
*/
public function __construct(
private readonly RunTranslateDto $runTranslateDto,
private readonly TranslationCompletedListener $translationCompletedListener,
private readonly RunTranslateDto $runTranslateDto,
private readonly AfterTranslateDto $afterTranslateDto,
) { }
/**
@@ -55,7 +55,7 @@ final class RunTranslate implements ShouldQueue, ShouldBeEncrypted
}
$translated->add($key, count($texts));
}
$chains[] = new AfterTranslate($groupName, $this->translationCompletedListener, $translated);
$chains[] = new AfterTranslate($groupName, $translated, $this->afterTranslateDto);
Bus::chain($chains)->dispatch();
}