From 8308c7c0d7ab61722d0e3a4bcc035eed0b5c1273 Mon Sep 17 00:00:00 2001 From: Gautier Masdupuy Date: Tue, 6 Jun 2023 16:26:01 +0200 Subject: [PATCH 1/5] WIP: test compatibility with Oro 5.1.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1cbd111..f537753 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "oro/platform": "4.2.*", + "oro/platform": ">=4.2.0 <5.2", "babymarkt/deepl-php-lib": "2.0.1" }, "autoload": { From 63daa9988399e29168b29919d283262b04f8de57 Mon Sep 17 00:00:00 2001 From: Gautier Masdupuy Date: Tue, 6 Jun 2023 16:40:42 +0200 Subject: [PATCH 2/5] WIP: update deepl php sdk --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f537753..700bde5 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "oro/platform": ">=4.2.0 <5.2", - "babymarkt/deepl-php-lib": "2.0.1" + "deeplcom/deepl-php": "1.4.0" }, "autoload": { "psr-4": { From a21f3e1e016f4899ee86c4aa3751d7e2dda82a34 Mon Sep 17 00:00:00 2001 From: Gautier Masdupuy Date: Wed, 7 Jun 2023 13:25:18 +0200 Subject: [PATCH 3/5] Update translate command to use the DeepL official deepl php sdk Remove free option in command since deepl automaticaly Remove unused class in use Update readme --- Command/TranslationExportCommand.php | 23 ++++++++++------------- Command/TranslationLoadCommand.php | 4 ++-- README.md | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Command/TranslationExportCommand.php b/Command/TranslationExportCommand.php index 71f84e2..c0282be 100644 --- a/Command/TranslationExportCommand.php +++ b/Command/TranslationExportCommand.php @@ -9,7 +9,8 @@ namespace Diglin\Bundle\DeeplBundle\Command; -use BabyMarkt\DeepL\DeepL; +use DeepL\Translator as DeepL; +use DeepL\TranslatorOptions; use Doctrine\ORM\Query\Expr\Join; use Oro\Bundle\TranslationBundle\Entity\Translation; use Oro\Bundle\TranslationBundle\Provider\LanguageProvider; @@ -84,11 +85,6 @@ public function configure() null, InputOption::VALUE_OPTIONAL, 'Deepl API Dev Key. API key is looked up 1) at the Oro Config, 2) via the cli parameter, 3) into the var/deepl-license.key' - )->addOption( - 'free-license', - null, - InputOption::VALUE_NONE, - 'if you use the free license API of Deepl' )->addOption( 'disable-deepl', 'd', @@ -197,6 +193,7 @@ public function execute(InputInterface $input, OutputInterface $output) 'english_value' => $translation['englishValue'], $locale => $translated, ]; + break; } $output->writeln(''); @@ -232,9 +229,11 @@ public function execute(InputInterface $input, OutputInterface $output) } if (isset($this->deepl)) { - $usageArray = $this->deepl->usage(); - $output->writeln(sprintf('You have used %s of %s in the current billing period.', $usageArray['character_count'], $usageArray['character_limit'])); + $usageArray = $this->deepl->getUsage(); + $output->writeln(sprintf('You have used %s of %s in the current billing period.', $usageArray->character->count, $usageArray->character->limit)); } + + return 0; } /** @@ -360,12 +359,10 @@ private function initDeepl(InputInterface $input): void { if (!$input->getOption('disable-deepl') && !$input->getOption('simulate')) { $apiKey = $this->getDeeplApiKey($input); - $endpointUrl = $input->getOption('free-license') ? 'api-free.deepl.com' : 'api.deepl.com'; - if (empty($apiKey)) { throw new \Exception('DeepL API Key not defined. Please, go to OroPlatform Backoffice, menu System > Configuration > System Configuration > Integrations > DeepL. Or provide the key by the parameter "deepl-api-key" or set the key into the var/deepl-license.key file.'); } else { - $this->deepl = new DeepL($apiKey, 2, $endpointUrl); + $this->deepl = new DeepL($apiKey); } } } @@ -379,8 +376,8 @@ private function translate(array $translation): string $localeLocale = explode('_', $translation['code']); $localeLang = $localeLocale[0];// e.g. de for german $text = str_replace($tagsToIgnore, $tagsIgnored, $translation['englishValue']); - $deeplTrans = $this->deepl->translate($text, $srcLang, $localeLang, 'xml', ['ignore']); + $deeplTrans = $this->deepl->translateText($text, $srcLang, $localeLang, ['tag_handling' => 'xml', 'ignore_tags' => 'ignore']); - return str_replace($tagsIgnored, $tagsToIgnore, $deeplTrans[0]['text']); + return str_replace($tagsIgnored, $tagsToIgnore, $deeplTrans->text); } } diff --git a/Command/TranslationLoadCommand.php b/Command/TranslationLoadCommand.php index 8e1bf48..ff666b7 100644 --- a/Command/TranslationLoadCommand.php +++ b/Command/TranslationLoadCommand.php @@ -17,8 +17,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\Process\Exception\ProcessFailedException; -use Symfony\Component\Process\Process; use Symfony\Component\Yaml\Yaml; use Symfony\Contracts\Translation\TranslatorInterface; @@ -171,5 +169,7 @@ public function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf('The file %s has been merged with %s with success.', $file, $target)); $output->writeln(sprintf('Then run bin/console --env=prod cache:clear && bin/console --env=prod oro:translation:load.')); + + return 0; } } diff --git a/README.md b/README.md index 8677674..8e95bfa 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Same as for the CSV export, on Production environment, you just need to let the ## Requirement -- OroPlatform 4.0.x | 4.1.x | 4.2.x (may work on previous versions but not tested) +- OroPlatform 4.0.x | 4.1.x | 4.2.x | 5.1.* (may work on previous versions but not tested) ## Configuration From 8813962698daff3c4d40a858e17821b1758ae0cb Mon Sep 17 00:00:00 2001 From: Gautier Masdupuy Date: Wed, 7 Jun 2023 13:29:23 +0200 Subject: [PATCH 4/5] Remove debug code --- Command/TranslationExportCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Command/TranslationExportCommand.php b/Command/TranslationExportCommand.php index c0282be..47eae36 100644 --- a/Command/TranslationExportCommand.php +++ b/Command/TranslationExportCommand.php @@ -193,7 +193,6 @@ public function execute(InputInterface $input, OutputInterface $output) 'english_value' => $translation['englishValue'], $locale => $translated, ]; - break; } $output->writeln(''); From c92845799ef2ac7a41fa5f7b7b736d5e527d90bc Mon Sep 17 00:00:00 2001 From: Gautier Masdupuy Date: Thu, 8 Jun 2023 12:02:07 +0200 Subject: [PATCH 5/5] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e95bfa..4e56d31 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Same as for the CSV export, on Production environment, you just need to let the ## Requirement -- OroPlatform 4.0.x | 4.1.x | 4.2.x | 5.1.* (may work on previous versions but not tested) +- OroPlatform 4.x, 5.0, 5.1 (may work on previous versions but not tested) ## Configuration