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
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 pycord_ext_i18n-1.0.5.tar.gz.
File metadata
- Download URL: pycord_ext_i18n-1.0.5.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2be23a220bd6a381344d83d68da28a66a2cb4c5eaec09b98d8cec67530faaad2
|
|
| MD5 |
5303f55098ad6970aeb92815c849948b
|
|
| BLAKE2b-256 |
18a6d70288fffba4d61a4323c7732682adee5abbed1330deb20bfcec496d8efb
|
File details
Details for the file pycord_ext_i18n-1.0.5-py3-none-any.whl.
File metadata
- Download URL: pycord_ext_i18n-1.0.5-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44ff4bb506301bc7baaa6490b45faf1cdd459cde579267c8ca9bf6fe8c43e0e4
|
|
| MD5 |
e9dab28859c2a285b35751de3d2aba05
|
|
| BLAKE2b-256 |
6759428a75489ff8c2f4ed6b1826aa40aa97d60d02c4a4758cde9fdcb750964e
|