Skip to content

Commit

Permalink
Merge pull request #2 from diglin/feature/compatibility-oro-5.1.0
Browse files Browse the repository at this point in the history
Feature/compatibility oro 5.1.0
  • Loading branch information
sylvainraye authored Jun 8, 2023
2 parents 774eea0 + c928457 commit 5ca4a7f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
22 changes: 9 additions & 13 deletions Command/TranslationExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -232,9 +228,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;
}

/**
Expand Down Expand Up @@ -360,12 +358,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);
}
}
}
Expand All @@ -379,8 +375,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);
}
}
4 changes: 2 additions & 2 deletions Command/TranslationLoadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -171,5 +169,7 @@ public function execute(InputInterface $input, OutputInterface $output)

$output->writeln(sprintf('<fg=green>The file %s has been merged with %s with success.</>', $file, $target));
$output->writeln(sprintf('<fg=yellow>Then run bin/console --env=prod cache:clear && bin/console --env=prod oro:translation:load.</>'));

return 0;
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.x, 5.0, 5.1 (may work on previous versions but not tested)

## Configuration

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
],
"require": {
"oro/platform": "4.2.*",
"babymarkt/deepl-php-lib": "2.0.1"
"oro/platform": ">=4.2.0 <5.2",
"deeplcom/deepl-php": "1.4.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 5ca4a7f

Please sign in to comment.