Internationalization (i18n)
Zero Ichi supports multiple languages for all user-facing messages. Currently includes English and Indonesian.
Setting Language
Change the bot's language for a specific chat:
/lang en # English
/lang id # IndonesianCheck the current language:
/langPer-Chat
Language is set per chat, so different groups can use different languages.
How It Works
All bot messages use translation keys that map to strings in locale files:
src/locales/
├── en.json # English
└── id.json # IndonesianThe bot uses the t() function to retrieve translated strings:
python
from core.i18n import t, t_error, t_success
# Basic translation
message = t("errors.group_only")
# With variables
message = t("poll.usage", prefix=ctx.prefix)
# Helper functions (auto-prepend symbols)
error_msg = t_error("errors.admin_required")
success_msg = t_success("rules.updated")Adding a New Language
- Copy
src/locales/en.jsontosrc/locales/<code>.json - Update the
_meta.labelfield with the language name - Translate all string values (keep the keys the same)
- The bot automatically detects new locale files on startup
Example: Adding Spanish (es)
bash
cp src/locales/en.json src/locales/es.json
# Edit src/locales/es.jsonsrc/locales/es.json:
json
{
"_meta": {
"label": "Español"
},
"errors": {
...
}
}Locale File Structure
Translations are organized with dot-notation keys:
json
{
"errors": {
"group_only": "This command can only be used in groups",
"admin_required": "You need to be an admin"
},
"poll": {
"title": "Poll",
"usage": "Usage: {prefix}poll \"Question\" \"Option 1\" \"Option 2\""
}
}Dynamic Values
Use {placeholder} for dynamic content:
| Placeholder | Description |
|---|---|
{prefix} | Bot command prefix |
{error} | Error message |
{duration} | Time duration |
{command} | Command name |
