Glossary v3

This commit is contained in:
2025-06-19 02:35:45 +00:00
parent 31c3a20061
commit b770ba83d6
5 changed files with 66 additions and 50 deletions

View File

@@ -22,7 +22,7 @@ class GenericmessageCommand extends SystemCommand
public function execute(): ServerResponse
{
global $deepl_api_key, $allowed_chat_ids;
global $deepl_api_key, $deepl_glossary_id, $allowed_chat_ids;
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
@@ -51,14 +51,9 @@ class GenericmessageCommand extends SystemCommand
TranslateTextOptions::TAG_HANDLING => 'html',
TranslateTextOptions::SPLIT_SENTENCES => 'on',
];
try {
$glosasaryConfig = json_decode(file_get_contents(__DIR__ . '/../../glossary.json'), true);
$targetLangKey = explode('-', $targetLang)[0];
if (isset($glosasaryConfig[$sourceLang][$targetLangKey])) {
$deeplOptions[TranslateTextOptions::GLOSSARY] = $glosasaryConfig[$sourceLang][$targetLangKey];
}
} catch(\Exception $e) {}
if (isset($deepl_glossary_id)) {
$deeplOptions[TranslateTextOptions::GLOSSARY] = $deepl_glossary_id;
}
$this->translator = new Translator($deepl_api_key);
try {