A simple translation library for discord bots
Project description
distrans
A simple package to translate your discord bot to different languages
Key Features
- Fast work and async support.
- The only requirement is disnake.
- next-translate-like file structure and syntax.
Installing
Python 3.8 or higher is required.
# Linux/macOS
python3 -m pip install -U distrans
# Windows
py -3 -m pip install -U distrans
Quick Example
Inline translation example
from distrans import TranslationInteractionBot
bot = TranslationInteractionBot(
directory="locales",
languages=["en", "fr", "es", "uk"]
)
@bot.slash_command()
async def ping(inter, language: str):
await inter.send(bot.get(
"common:greeting",
code=language,
values={"name": inter.user.name}
)
)
def main():
bot.run("TOKEN")
if __name__ == "__main__":
main()
Using async/await
translated = await bot.t(
"common:greeting",
code=language,
values={"name": inter.user.name}
)
locales/en/common.json
{
"greeting": "Hello, $name!"
}
locales/fr/common.json
{
"greeting": "Bonjour, $name!"
}
locales/es/common.json
{
"greeting": "Hola, $name!"
}
locales/uk/common.json
{
"greeting": "Привіт, $name!"
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file distrans-1.0.0-py3-none-any.whl.
File metadata
- Download URL: distrans-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7c4781686e12fb1d2f13e720f7db0a493f71d1c14510281fa9cf3a86f036467
|
|
| MD5 |
21754f56c07767a689968c6f0632dcd0
|
|
| BLAKE2b-256 |
0bfa2422bb894b2a2f323fe89531fba0a899c7cee1c4e80972db1f39a8297505
|