translategram
v0.4.0 2023-10-22
TranslateGram은 Telegram Bots의 번역 기능을 제공하는 Python 패키지입니다. 여러 번역 서비스를 사용하고 지원합니다.
PIP를 사용하여 TranslateGram을 설치할 수 있습니다.
pip install translategram
message 라고 함). 유형은 string 이어야합니다. @ translator . handler_translator ( message = "Welcome to our community!" )
async def login ( update : Update , context : ContextTypes . DEFAULT_TYPE , message : str ) -> None :
await context . bot . send_message (
chat_id = update . effective_chat . id if update . effective_chat else 0 ,
text = message
) login_handler = CommandHandler ( 'login' , login ) from translategram import PythonTelegramBotTranslator , MtranslateTranslatorService
translator = PythonTelegramBotTranslator ( MtranslateTranslatorService ) import logging
from telegram . ext import ApplicationBuilder , ContextTypes , CommandHandler
from telegram import Update
from translategram import PythonTelegramBotTranslator , MtranslateTranslatorService
translator = PythonTelegramBotTranslator ( MtranslateTranslatorService )
TOKEN = 'YOUR_TOKEN'
logging . basicConfig (
format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ,
level = logging . INFO
)
logger = logging . getLogger ( __name__ )
@ translator . handler_translator ( message = "Welcome to our community!" )
async def login ( update : Update , context : ContextTypes . DEFAULT_TYPE , message : str ) -> None :
await context . bot . send_message (
chat_id = update . effective_chat . id if update . effective_chat else 0 ,
text = message
)
@ translator . handler_translator ( message = "This bot is very simple. You can just login with the /login command and that is it!" )
async def start ( update : Update , context : ContextTypes . DEFAULT_TYPE , message : str ) -> None :
await context . bot . send_message (
chat_id = update . effective_chat . id if update . effective_chat else 0 ,
text = message
)
if __name__ == '__main__' :
application = ApplicationBuilder (). token ( TOKEN ). build ()
login_handler = CommandHandler ( 'login' , login )
start_handler = CommandHandler ( 'start' , start )
application . add_handler ( login_handler )
application . add_handler ( start_handler )
application . run_polling ()이 프로젝트는 MIT 라이센스의 조건에 따라 라이센스가 부여됩니다.