HTML handling v2

This commit is contained in:
2026-05-21 19:58:16 +00:00
parent 36f2b26ac7
commit 393779ab2f
3 changed files with 10 additions and 12 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
"type": "project", "type": "project",
"require": { "require": {
"php": ">=8.1", "php": ">=8.1",
"deeplcom/deepl-php": "^1.12", "deeplcom/deepl-php": "^1.18",
"longman/telegram-bot": "*", "longman/telegram-bot": "*",
"lucadevelop/telegram-entities-decoder": "^1.3" "lucadevelop/telegram-entities-decoder": "^1.3"
}, },
Generated
+7 -7
View File
@@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "ddef5561d74db6ff0a26bdf886e71bd0", "content-hash": "85f6371654752b457d71015fa200e9a6",
"packages": [ "packages": [
{ {
"name": "deeplcom/deepl-php", "name": "deeplcom/deepl-php",
"version": "v1.12.0", "version": "v1.18.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/DeepLcom/deepl-php.git", "url": "https://github.com/DeepLcom/deepl-php.git",
"reference": "b9a7e0385d27a99b7756ebf95e953785b90e8161" "reference": "ca53d6e6907a71c47729ab160f0bbcbc059bed02"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/DeepLcom/deepl-php/zipball/b9a7e0385d27a99b7756ebf95e953785b90e8161", "url": "https://api.github.com/repos/DeepLcom/deepl-php/zipball/ca53d6e6907a71c47729ab160f0bbcbc059bed02",
"reference": "b9a7e0385d27a99b7756ebf95e953785b90e8161", "reference": "ca53d6e6907a71c47729ab160f0bbcbc059bed02",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -65,9 +65,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/DeepLcom/deepl-php/issues", "issues": "https://github.com/DeepLcom/deepl-php/issues",
"source": "https://github.com/DeepLcom/deepl-php/tree/v1.12.0" "source": "https://github.com/DeepLcom/deepl-php/tree/v1.18.0"
}, },
"time": "2025-04-25T20:00:25+00:00" "time": "2026-04-09T17:49:42+00:00"
}, },
{ {
"name": "guzzlehttp/guzzle", "name": "guzzlehttp/guzzle",
+2 -4
View File
@@ -76,6 +76,7 @@ class GenericmessageCommand extends SystemCommand
]; ];
if ($htmlMode) { if ($htmlMode) {
$deeplOptions[TranslateTextOptions::TAG_HANDLING] = 'html'; $deeplOptions[TranslateTextOptions::TAG_HANDLING] = 'html';
$deeplOptions[TranslateTextOptions::TAG_HANDLING_VERSION] = 'v2';
} }
if (isset($deepl_glossary_id)) { if (isset($deepl_glossary_id)) {
$deeplOptions[TranslateTextOptions::GLOSSARY] = $deepl_glossary_id; $deeplOptions[TranslateTextOptions::GLOSSARY] = $deepl_glossary_id;
@@ -85,15 +86,12 @@ class GenericmessageCommand extends SystemCommand
try { try {
if ($htmlMode) { if ($htmlMode) {
$text = (new EntityDecoder('HTML'))->decode(json_decode($message->toJson())); $text = (new EntityDecoder('HTML'))->decode(json_decode($message->toJson()));
// $text = str_replace("\n", '<br />', $text);
} }
$translated = $this->translator->translateText($text, $sourceLang, $targetLang, $deeplOptions); $translated = $this->translator->translateText($text, $sourceLang, $targetLang, $deeplOptions);
$translated = $translated->text; $translated = $translated->text;
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->replyToChat(get_class($e) . ': ' . $e->getMessage()); // ?? var_export($e, true) return $this->replyToChat(get_class($e) . ': ' . $e->getMessage());
} }
$translated = str_replace('&lt;BR /&gt;', "\n", $translated);
// $translated = str_replace('<br />', "\n", $translated);
$forwardedFrom = $message->getForwardFrom(); $forwardedFrom = $message->getForwardFrom();
if ($forwardedFrom) { if ($forwardedFrom) {