Internationalization for pycord
Project description
pycord-i18n
Internationalization for Pycord
Key Features
- Translated responses
- Command name & description localization
- Based on user & server locale (no need for storage!)
Usage
-
Setup your internationalization files just like sample-german.json.
-
Load your files:
import json
with open("sample-german.json", "r") as f:
german = json.load(f)
...
- Create an I18n object:
from pycord.i18n import I18n, _
i18n = I18n(bot, de=german)
# de is the locale code for German
# response translations will be based on the guild's locale, you can make the bot consider the user's locale too by using the following:
i18n = I18n(bot, consider_user_locale=True, de=german)
# all valid locales: da, de, en_GB, en_US, es_ES, fr, hr, it, lt, hu, nl, no, pl, pt_BR, ro, fi, sv_SE, vi, tr, cs, el, bg, ru, uk, hi, th, zh_CN, ja, zh_TW, ko
- Internationalize your commands:
@i18n.localize # command name and description localization
@bot.slash_command()
async def hello(ctx):
await ctx.respond(_("Hello, this sentence is in English"))
# "_()" does the translation
# if you don't want to use `@localize` on every command, simply use the following method after adding the commands to the bot:
i18n.localize_commands()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pycord-i18n-1.0.0.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for pycord_i18n-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b351e23f30571fede22c34cbd7148952a8e956b84a1ef65e36da5b909776a664 |
|
MD5 | 8c54303664fb1f1849b93c6c117bef80 |
|
BLAKE2b-256 | aa67ba198d6d856884e0ba1112b0cace790b5f8d7f23e0788f05657a473408e8 |