Glossary v3
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"deeplcom/deepl-php": "^1.1.0",
|
||||
"deeplcom/deepl-php": "^1.12",
|
||||
"longman/telegram-bot": "*",
|
||||
"lucadevelop/telegram-entities-decoder": "^1.3"
|
||||
},
|
||||
|
||||
28
composer.lock
generated
28
composer.lock
generated
@@ -4,20 +4,20 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "be8152ca483086150648bd025aef879e",
|
||||
"content-hash": "ddef5561d74db6ff0a26bdf886e71bd0",
|
||||
"packages": [
|
||||
{
|
||||
"name": "deeplcom/deepl-php",
|
||||
"version": "v1.11.1",
|
||||
"version": "v1.12.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DeepLcom/deepl-php.git",
|
||||
"reference": "004cf73864e8547ece7e49a2b08ed7a2d6672d9c"
|
||||
"reference": "b9a7e0385d27a99b7756ebf95e953785b90e8161"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/DeepLcom/deepl-php/zipball/004cf73864e8547ece7e49a2b08ed7a2d6672d9c",
|
||||
"reference": "004cf73864e8547ece7e49a2b08ed7a2d6672d9c",
|
||||
"url": "https://api.github.com/repos/DeepLcom/deepl-php/zipball/b9a7e0385d27a99b7756ebf95e953785b90e8161",
|
||||
"reference": "b9a7e0385d27a99b7756ebf95e953785b90e8161",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -65,9 +65,9 @@
|
||||
],
|
||||
"support": {
|
||||
"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",
|
||||
@@ -932,16 +932,16 @@
|
||||
},
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
"version": "v3.5.1",
|
||||
"version": "v3.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/deprecation-contracts.git",
|
||||
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6"
|
||||
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
|
||||
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
|
||||
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
|
||||
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -954,7 +954,7 @@
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.5-dev"
|
||||
"dev-main": "3.6-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@@ -979,7 +979,7 @@
|
||||
"description": "A generic function and convention to trigger deprecation notices",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1"
|
||||
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -995,7 +995,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-09-25T14:20:29+00:00"
|
||||
"time": "2024-09-25T14:21:43+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
$bot_api_key = '1234567890:Telegram_bot_api_key';
|
||||
$bot_username = 'telegram_bot_username';
|
||||
$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_glossary_id = 'some-uuid-12345-abcde'; // or null or commented out
|
||||
$allowed_chat_ids = [123, 456, -123];
|
||||
|
||||
@@ -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];
|
||||
|
||||
if (isset($deepl_glossary_id)) {
|
||||
$deeplOptions[TranslateTextOptions::GLOSSARY] = $deepl_glossary_id;
|
||||
}
|
||||
} catch(\Exception $e) {}
|
||||
|
||||
$this->translator = new Translator($deepl_api_key);
|
||||
try {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
require __DIR__ . '/env.php';
|
||||
|
||||
$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',
|
||||
'兽人' => 'furry character',
|
||||
'兽控' => 'furry',
|
||||
@@ -17,12 +18,8 @@ $zhToEnGlossary = $deeplClient->createGlossary('Furry ZH to EN', 'zh', 'en', \De
|
||||
'哇塞' => 'wa sai',
|
||||
'色色' => 'sese',
|
||||
'変态' => 'hentai',
|
||||
]));
|
||||
echo "Created '$zhToEnGlossary->name' ($zhToEnGlossary->glossaryId) " .
|
||||
"$zhToEnGlossary->sourceLang to $zhToEnGlossary->targetLang " .
|
||||
"containing $zhToEnGlossary->entryCount entries\n";
|
||||
|
||||
$enToZhGlossary = $deeplClient->createGlossary('Furry EN to ZH', 'en', 'zh', \DeepL\GlossaryEntries::fromEntries([
|
||||
]);
|
||||
$dicts []= new \DeepL\MultilingualGlossaryDictionaryEntries( 'en', 'zh', [
|
||||
'fursona' => '兽设',
|
||||
'furry character' => '兽人',
|
||||
'furry' => '兽控',
|
||||
@@ -40,20 +37,44 @@ $enToZhGlossary = $deeplClient->createGlossary('Furry EN to ZH', 'en', 'zh', \De
|
||||
'wa sai' => '哇塞',
|
||||
'commission' => '委托',
|
||||
'dalao' => '大佬',
|
||||
]));
|
||||
echo "Created '$enToZhGlossary->name' ($enToZhGlossary->glossaryId) " .
|
||||
"$enToZhGlossary->sourceLang to $enToZhGlossary->targetLang " .
|
||||
"containing $enToZhGlossary->entryCount entries\n";
|
||||
]);
|
||||
$dicts []= new \DeepL\MultilingualGlossaryDictionaryEntries( 'en', 'ja', [
|
||||
'fursuit' => '着ぐるみ',
|
||||
'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([
|
||||
'zh' => ['en' => $zhToEnGlossary->glossaryId],
|
||||
'en' => ['zh' => $enToZhGlossary->glossaryId],
|
||||
]));
|
||||
|
||||
echo("\nCleaning up other unused glossaries...\n");
|
||||
foreach ($deeplClient->listGlossaries() as $glossary) {
|
||||
if (!(in_array($glossary->glossaryId, [$enToZhGlossary->glossaryId, $zhToEnGlossary->glossaryId]))) {
|
||||
echo("Unused glossary found, deleting '$glossary->name' ($glossary->glossaryId)\n");
|
||||
$deeplClient->deleteGlossary($glossary);
|
||||
$GLOSSARY_NAME = 'Furry glossary';
|
||||
echo("Checking for existing copy of \"$GLOSSARY_NAME\"...\n");
|
||||
foreach ($deeplClient->listMultilingualGlossaries() as $glossary) {
|
||||
if ($glossary->name === $GLOSSARY_NAME) {
|
||||
echo("Found existing ID $glossary->glossaryId, updating in-place\n");
|
||||
$found = true;
|
||||
foreach ($dicts as $dict) {
|
||||
echo ('- Replacing dictionary for ' . $dict->sourceLang . ' to ' . $dict->targetLang . "\n");
|
||||
$deeplClient->replaceMultilingualGlossaryDictionary($glossary, $dict);
|
||||
}
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user