- Translated responses
- Command name, description & option localization
- Based on user & server locale (no need for storage!)
To install this extension, run the corresponding command:
# linux / macOS
python3 -m pip install pycord-i18n
# windows
python -m pip install pycord-i18n
-
Setup your internationalization files just like sample-german.json. Note that all fields are optional and you can use whichever file format you want as long as you pass the translations into I18n in the given format.
-
Load your files:
import json
with open("sample-german.json", "r") as f:
german_localization = json.load(f)
- Create an I18n object:
from pycord.i18n import I18n, _
i18n = I18n(bot, de=german_localization)
# "de" is the German locale
# string translations will be based on the guild's locale by default
# you can make the bot consider the user's locale by using the following:
i18n = I18n(bot, consider_user_locale=True, de=german_localization)
# all valid locales:
# id, da, de, en-GB, en-US, es-ES, es-419, 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()
- Fixed an issue with Pycord v2.5 compatibility
- Added formatting support
- Added option localization support