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

@@ -3,7 +3,7 @@
"type": "project", "type": "project",
"require": { "require": {
"php": ">=8.1", "php": ">=8.1",
"deeplcom/deepl-php": "^1.1.0", "deeplcom/deepl-php": "^1.12",
"longman/telegram-bot": "*", "longman/telegram-bot": "*",
"lucadevelop/telegram-entities-decoder": "^1.3" "lucadevelop/telegram-entities-decoder": "^1.3"
}, },

28
composer.lock generated
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": "be8152ca483086150648bd025aef879e", "content-hash": "ddef5561d74db6ff0a26bdf886e71bd0",
"packages": [ "packages": [
{ {
"name": "deeplcom/deepl-php", "name": "deeplcom/deepl-php",
"version": "v1.11.1", "version": "v1.12.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/DeepLcom/deepl-php.git", "url": "https://github.com/DeepLcom/deepl-php.git",
"reference": "004cf73864e8547ece7e49a2b08ed7a2d6672d9c" "reference": "b9a7e0385d27a99b7756ebf95e953785b90e8161"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/DeepLcom/deepl-php/zipball/004cf73864e8547ece7e49a2b08ed7a2d6672d9c", "url": "https://api.github.com/repos/DeepLcom/deepl-php/zipball/b9a7e0385d27a99b7756ebf95e953785b90e8161",
"reference": "004cf73864e8547ece7e49a2b08ed7a2d6672d9c", "reference": "b9a7e0385d27a99b7756ebf95e953785b90e8161",
"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.11.1" "source": "https://github.com/DeepLcom/deepl-php/tree/v1.12.0"
}, },
"time": "2025-01-17T09:36:14+00:00" "time": "2025-04-25T20:00:25+00:00"
}, },
{ {
"name": "guzzlehttp/guzzle", "name": "guzzlehttp/guzzle",
@@ -932,16 +932,16 @@
}, },
{ {
"name": "symfony/deprecation-contracts", "name": "symfony/deprecation-contracts",
"version": "v3.5.1", "version": "v3.6.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git", "url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6" "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6", "reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -954,7 +954,7 @@
"name": "symfony/contracts" "name": "symfony/contracts"
}, },
"branch-alias": { "branch-alias": {
"dev-main": "3.5-dev" "dev-main": "3.6-dev"
} }
}, },
"autoload": { "autoload": {
@@ -979,7 +979,7 @@
"description": "A generic function and convention to trigger deprecation notices", "description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1" "source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
}, },
"funding": [ "funding": [
{ {
@@ -995,7 +995,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-09-25T14:20:29+00:00" "time": "2024-09-25T14:21:43+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],

View File

@@ -2,9 +2,9 @@
// Rename me to env.php // Rename me to env.php
$bot_api_key = '1234567890:Telegram_bot_api_key'; $bot_api_key = '1234567890:Telegram_bot_api_key';
$bot_username = 'telegram_bot_username'; $bot_username = 'telegram_bot_username';
$hook_url = 'https://my.server.com/path/to/hook.php'; $hook_url = 'https://my.server.com/path/to/hook.php';
putenv('DEEPL_API_KEY=some-uuid-12345-abcde:fx');
$deepl_api_key = 'some-uuid-12345-abcde:fx'; $deepl_api_key = 'some-uuid-12345-abcde:fx';
$deepl_glossary_id = 'some-uuid-12345-abcde'; // or null or commented out
$allowed_chat_ids = [123, 456, -123]; $allowed_chat_ids = [123, 456, -123];

View File

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

View File

@@ -1,9 +1,10 @@
<?php <?php
require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/env.php'; require __DIR__ . '/env.php';
$deeplClient = new \DeepL\DeepLClient($deepl_api_key); $deeplClient = new \DeepL\DeepLClient($deepl_api_key);
$zhToEnGlossary = $deeplClient->createGlossary('Furry ZH to EN', 'zh', 'en', \DeepL\GlossaryEntries::fromEntries([
$dicts = [];
$dicts []= new \DeepL\MultilingualGlossaryDictionaryEntries('zh', 'en', [
'兽设' => 'fursona', '兽设' => 'fursona',
'兽人' => 'furry character', '兽人' => 'furry character',
'兽控' => 'furry', '兽控' => 'furry',
@@ -17,12 +18,8 @@ $zhToEnGlossary = $deeplClient->createGlossary('Furry ZH to EN', 'zh', 'en', \De
'哇塞' => 'wa sai', '哇塞' => 'wa sai',
'色色' => 'sese', '色色' => 'sese',
'変态' => 'hentai', '変态' => 'hentai',
])); ]);
echo "Created '$zhToEnGlossary->name' ($zhToEnGlossary->glossaryId) " . $dicts []= new \DeepL\MultilingualGlossaryDictionaryEntries( 'en', 'zh', [
"$zhToEnGlossary->sourceLang to $zhToEnGlossary->targetLang " .
"containing $zhToEnGlossary->entryCount entries\n";
$enToZhGlossary = $deeplClient->createGlossary('Furry EN to ZH', 'en', 'zh', \DeepL\GlossaryEntries::fromEntries([
'fursona' => '兽设', 'fursona' => '兽设',
'furry character' => '兽人', 'furry character' => '兽人',
'furry' => '兽控', 'furry' => '兽控',
@@ -40,20 +37,44 @@ $enToZhGlossary = $deeplClient->createGlossary('Furry EN to ZH', 'en', 'zh', \De
'wa sai' => '哇塞', 'wa sai' => '哇塞',
'commission' => '委托', 'commission' => '委托',
'dalao' => '大佬', 'dalao' => '大佬',
])); ]);
echo "Created '$enToZhGlossary->name' ($enToZhGlossary->glossaryId) " . $dicts []= new \DeepL\MultilingualGlossaryDictionaryEntries( 'en', 'ja', [
"$enToZhGlossary->sourceLang to $enToZhGlossary->targetLang " . 'fursuit' => '着ぐるみ',
"containing $enToZhGlossary->entryCount entries\n"; 'vore' => '丸呑み',
'bussy' => 'ケツマンコ',
'hentai' => '変態',
'oppai' => 'おっぱい',
'ochinchin' => 'おちんちん',
'kemoner' => 'ケモナー',
'furry' => 'ファーリー',
]);
$dicts []= new \DeepL\MultilingualGlossaryDictionaryEntries( 'ja', 'en', [
'着ぐるみ' => 'fursuit',
'丸呑み' => 'vore',
'ケツマンコ' => 'bussy',
'変態' => 'hentai',
'おっぱい' => 'oppai',
'おちんちん' => 'ochinchin',
'ケモナー' => 'kemoner',
'ファーリー' => 'furry',
]);
file_put_contents(__DIR__ . '/glossary.json', json_encode([ $GLOSSARY_NAME = 'Furry glossary';
'zh' => ['en' => $zhToEnGlossary->glossaryId], echo("Checking for existing copy of \"$GLOSSARY_NAME\"...\n");
'en' => ['zh' => $enToZhGlossary->glossaryId], foreach ($deeplClient->listMultilingualGlossaries() as $glossary) {
])); if ($glossary->name === $GLOSSARY_NAME) {
echo("Found existing ID $glossary->glossaryId, updating in-place\n");
echo("\nCleaning up other unused glossaries...\n"); $found = true;
foreach ($deeplClient->listGlossaries() as $glossary) { foreach ($dicts as $dict) {
if (!(in_array($glossary->glossaryId, [$enToZhGlossary->glossaryId, $zhToEnGlossary->glossaryId]))) { echo ('- Replacing dictionary for ' . $dict->sourceLang . ' to ' . $dict->targetLang . "\n");
echo("Unused glossary found, deleting '$glossary->name' ($glossary->glossaryId)\n"); $deeplClient->replaceMultilingualGlossaryDictionary($glossary, $dict);
$deeplClient->deleteGlossary($glossary); }
echo("Done");
exit(0);
} }
} }
echo("No existing glossary found, creating a new one\n");
$myGlossary = $deeplClient->createMultilingualGlossary('Furry glossary', $dicts);
echo("Glossary created: $myGlossary->name ID: $myGlossary->glossaryId\n");
echo("put this id in .env file\n");