This repository has been archived on 2025-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
natsuko/utils/translate.py

42 lines
1018 B
Python
Raw Normal View History

2023-05-03 19:53:01 +03:00
from bot import db
2023-05-15 23:22:19 +03:00
from discord.app_commands import TranslationContextLocation as trans_loc
from discord import app_commands
2023-05-03 19:53:01 +03:00
def region_to_str(region):
# if region == discord.VoiceRegion.russia:
# return "RU"
# elif region == discord.VoiceRegion.japan:
# return "JP"
# else:
return "RU"
def translate(string, region):
if string is not None:
if string.startswith("$"):
string = string.replace("$", "")
string = string.split("_")
print(region)
pack = db.strings.find_one({"lang": region})
print(pack)
for i in string:
pack = pack[i]
print(pack)
return pack
else:
return string
2023-05-15 23:22:19 +03:00
async def get_text(inter, location, string):
data = await inter.translate(
2023-05-16 12:31:43 +03:00
string=app_commands.locale_str(string),
2023-05-15 23:22:19 +03:00
locale=inter.locale,
2023-05-16 12:31:43 +03:00
data=location
2023-05-15 23:22:19 +03:00
)
return data or string