A regular localization Library for pycord.
Project description
Pycord_ext_i18n
A regular localization Library for pycord.
Installation
To install the pycord_ext_i18n, you can just run the following command:
# Windows
pip install pycord_ext_i18n
# Linux/MacOS
python3 -m pip install pycord_ext_i18n
Prepare
First, You will need to a locale configuration file (*.json) to store your command parameter or string. A locale configuration file internal structure will be like it:
{
"command.{command_name}.name": "help", #your command_name name.
"command.{command_name}.description": "help_description", #your command_name description.
"hello": "你好" #this is string.
}
And, save your locale configuration file to locale folder. The name is the country code you want! (like Zh-TW, en-US...)
Basic Usage
Usage: Get a text.
from pycord_ext_i18n import I18n
i18n = I18n()
i18n.load('./locale')
print(i18n.get_text("hello", "zh-TW", None)) #Print: 你好
Usage: Use localize_slash_command to localize your slash command (Remember configuration file).
from discord import ApplicationContext
from discord.ext import commands
from pycord_ext_i18n import I18n
i18n = I18n()
class ExampleCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@i18n.localize_slash_command()
async def test(self, ctx: ApplicationContext):
await ctx.response.send_message(content=f"My command name is {ctx.command.name}!")
def setup(bot):
bot.add_cog(ExampleCog(bot))
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_ext_i18n-1.0.5.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for pycord_ext_i18n-1.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44ff4bb506301bc7baaa6490b45faf1cdd459cde579267c8ca9bf6fe8c43e0e4 |
|
MD5 | e9dab28859c2a285b35751de3d2aba05 |
|
BLAKE2b-256 | 6759428a75489ff8c2f4ed6b1826aa40aa97d60d02c4a4758cde9fdcb750964e |