diff --git a/CHANGELOG.md b/CHANGELOG.md index 6685312..d3dc5fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Model/Translator/DeepL.php b/Model/Translator/DeepL.php index efc6833..f23ce93 100644 --- a/Model/Translator/DeepL.php +++ b/Model/Translator/DeepL.php @@ -12,12 +12,7 @@ class DeepL implements TranslatorInterface { - const REGIONAL_VARIANTS_LANGUAGES = [ - 'en', - 'pt', - 'es', - 'zh' - ]; + protected ?string $normalizedTargetLang = null; protected ?DeepLTranslator $translator = null; @@ -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; } }