Add localization support to your interactions.py bot
Project description
interactions-i18n
Add localization support to your interactions.py bot
Installation
pip install --upgrade interactions-i18n
Usage
import interactions
client = interactions.Client(...)
# Load an i18n extension
i18n = client.load("interactions.ext.i18n")
# Load a folder with locales
# Also you can load json file only
i18n.load("./locales/")
...
client.start()
Creating a locale file
- Choose a language you want and find their code in the Discord Locales Docs
- Create a
[CODE].json
file with found code in the folder with locales.
Getting and setting keys
Let's create a command with name info
with some subcommands
@client.command()
async def info(ctx: interactions.CommandContext):
...
# Key for command name will be `INFO_NAME`
# Key for command description will be `INFO_DESCRIPTION`
@info.group()
async def my_group(ctx: interactions.CommandContext):
...
# Keys are `MY_GROUP_NAME` for name and `MY_GROUP_DESCRIPTION` for description
@my_group.subcommand()
@interactions.option(key="info_member_opt") # `key` is optional. Keys for this option you can get from option name
async def user(ctx: interactions.CommandContext, member: interactions.Member):
...
# Keys for subcommand are `USER_NAME` for name and `USER_DESCRIPTION` for description
# Keys for option are `INFO_MEMBER_OPT_NAME` for name and `INFO_MEMBER_OPT_DESCRIPTION` for description
How will look our json file
locales/de.json
{
"INFO_NAME": "...",
"INFO_DESCRIPTION": "...",
"MY_GROUP_NAME": "...",
"MY_GROUP_DESCRIPTION": "...",
"MEMBER_NAME": "...",
"MEMBER_DESCRIPTION": "...",
"INFO_MEMBER_OPT_NAME": "...",
"INFO_MEMBER_OPT_DESCRIPTION": "..."
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for interactions_i18n-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a72b2d6b9324f57d2b489a55f6ee931ebd8307ee0add034754a25c6216b2ffb |
|
MD5 | 732131dcf9f7c8420a0132dd4ccdfdfb |
|
BLAKE2b-256 | 140b8d4e50f350d2f5d783389d1ec4da93f246298a48f3eb7af9e89e4f954565 |