From 32685cf9dc02aaefda7ea2a21b346f7409008443 Mon Sep 17 00:00:00 2001 From: drejmanMacopedia Date: Mon, 5 Jun 2023 14:19:21 +0200 Subject: [PATCH] Translate attributes of one produt at once. Refactor translation process --- .../ConstraintCollectionProvider/TranslateAttributes.php | 2 +- .../JobParameters/DefaultValueProvider/TranslateAttributes.php | 2 +- .../Connector/Tasklet/ValidateOpenAiKeyTasklet.php | 3 ++- src/Macopedia/OpenAiTranslator/Translator/OpenAiTranslator.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Macopedia/OpenAiTranslator/Connector/Job/JobParameters/ConstraintCollectionProvider/TranslateAttributes.php b/src/Macopedia/OpenAiTranslator/Connector/Job/JobParameters/ConstraintCollectionProvider/TranslateAttributes.php index e247486..2de0fa0 100644 --- a/src/Macopedia/OpenAiTranslator/Connector/Job/JobParameters/ConstraintCollectionProvider/TranslateAttributes.php +++ b/src/Macopedia/OpenAiTranslator/Connector/Job/JobParameters/ConstraintCollectionProvider/TranslateAttributes.php @@ -50,4 +50,4 @@ public function supports(JobInterface $job): bool { return in_array($job->getName(), $this->supportedJobNames); } -} \ No newline at end of file +} diff --git a/src/Macopedia/OpenAiTranslator/Connector/Job/JobParameters/DefaultValueProvider/TranslateAttributes.php b/src/Macopedia/OpenAiTranslator/Connector/Job/JobParameters/DefaultValueProvider/TranslateAttributes.php index 4cf2dc1..133ec0b 100644 --- a/src/Macopedia/OpenAiTranslator/Connector/Job/JobParameters/DefaultValueProvider/TranslateAttributes.php +++ b/src/Macopedia/OpenAiTranslator/Connector/Job/JobParameters/DefaultValueProvider/TranslateAttributes.php @@ -40,4 +40,4 @@ public function supports(JobInterface $job): bool { return in_array($job->getName(), $this->supportedJobNames); } -} \ No newline at end of file +} diff --git a/src/Macopedia/OpenAiTranslator/Connector/Tasklet/ValidateOpenAiKeyTasklet.php b/src/Macopedia/OpenAiTranslator/Connector/Tasklet/ValidateOpenAiKeyTasklet.php index 2dd67ca..7bf50c4 100644 --- a/src/Macopedia/OpenAiTranslator/Connector/Tasklet/ValidateOpenAiKeyTasklet.php +++ b/src/Macopedia/OpenAiTranslator/Connector/Tasklet/ValidateOpenAiKeyTasklet.php @@ -7,6 +7,7 @@ use Akeneo\Tool\Component\Batch\Job\BatchStatus; use Akeneo\Tool\Component\Batch\Model\StepExecution; use Akeneo\Tool\Component\Connector\Step\TaskletInterface; +use Exception; class ValidateOpenAiKeyTasklet implements TaskletInterface { @@ -15,7 +16,7 @@ class ValidateOpenAiKeyTasklet implements TaskletInterface public function execute(): void { if (empty($this->stepExecution->getJobParameters()->get('open_ai_key'))) { - $this->stepExecution->addFailureException(new \Exception('OpenAI key is not set')); + $this->stepExecution->addFailureException(new Exception('OpenAI key is not set')); $this->stepExecution->setStatus(new BatchStatus(BatchStatus::FAILED)); } } diff --git a/src/Macopedia/OpenAiTranslator/Translator/OpenAiTranslator.php b/src/Macopedia/OpenAiTranslator/Translator/OpenAiTranslator.php index ad920ba..718aa19 100644 --- a/src/Macopedia/OpenAiTranslator/Translator/OpenAiTranslator.php +++ b/src/Macopedia/OpenAiTranslator/Translator/OpenAiTranslator.php @@ -22,7 +22,7 @@ public function translate(string $text, Language $targetLanguageCode): ?string ->ask('user', sprintf(self::MESSAGE, $targetLanguageCode->asText(), $text)); if ($answer !== null) { - $answer = preg_replace('/(\(Note.*)/','',$answer); + $answer = preg_replace('/(\(Note.*)/', '', $answer); } return $answer;