Added translations
This commit is contained in:
parent
fa34f8510d
commit
937dd76fe7
3 changed files with 58 additions and 3 deletions
25
cogs/api/translation.py
Normal file
25
cogs/api/translation.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
from util import checking
|
||||
from api import translation
|
||||
|
||||
class Translation(commands.Cog):
|
||||
|
||||
def __init__(self, client: discord.Client):
|
||||
self.client = client
|
||||
|
||||
@commands.command(name="translate", description="Translates the given text", usage="translate <ISO CountryCode>", aliases=["tl"])
|
||||
@commands.check(checking.is_author_bot)
|
||||
async def translate(self, ctx: commands.Context, language: str, *message: str):
|
||||
# Get language code
|
||||
code = translation.name_to_ISO(language)
|
||||
text = ' '.join(message)
|
||||
if code == "":
|
||||
await ctx.send(f"There is no language named {language}.")
|
||||
return
|
||||
|
||||
translated = translation.translate(text, code)
|
||||
await ctx.send(translated)
|
||||
|
||||
def setup(client: discord.Client):
|
||||
client.add_cog(Translation(client))
|
Loading…
Add table
Add a link
Reference in a new issue