Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Automatic Translation

## [2.2.0] - 23/06/2026
### Fixed
- Fix cron expression
### Changed
- Paginate per 100 to prevent failure on large catalogs
- Use v2/languages endpoint for Deepl target language normalization

## [2.1.2] - 21/04/2026
### Fixed
- PHP 8.4 and 8.5 compatibility
Expand Down
34 changes: 21 additions & 13 deletions Model/Translator/DeepL.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@

class DeepL implements TranslatorInterface
{
const REGIONAL_VARIANTS_LANGUAGES = [
'en',
'pt',
'es',
'zh'
];
protected ?string $normalizedTargetLang = null;

protected ?DeepLTranslator $translator = null;

Expand Down Expand Up @@ -65,14 +60,27 @@ public function translate(string $text, string $targetLang, ?string $sourceLang
*/
protected function normalizeTargetLang(string $lang): string
{
if (($lang[2] ?? '') !== '_') {
return $lang;
}
if (!$this->normalizedTargetLang) {
if (($lang[2] ?? '') !== '_') {
$this->normalizedTargetLang = $lang;
return $this->normalizedTargetLang;
}

$lang = str_replace('_', '-', $lang);
$lang = str_replace('_', '-', $lang);
$targetLanguages = $this->translator->getTargetLanguages();

return in_array(substr($lang, 0, 2), self::REGIONAL_VARIANTS_LANGUAGES, true)
? $lang
: substr($lang, 0, 2);
/**
* @var \DeepL\Language $targetLanguage
*/
foreach ($targetLanguages as $targetLanguage) {
if (strtolower($targetLanguage->code) === strtolower($lang)) {
$this->normalizedTargetLang = $lang;
return $this->normalizedTargetLang;
}
}

$this->normalizedTargetLang = substr($lang, 0, 2);
}
return $this->normalizedTargetLang;
}
}