Skip to content

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    # Indonesian

Check the current language:

/lang

Per-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    # Indonesian

The 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 ​

  1. Copy src/locales/en.json to src/locales/<code>.json
  2. Update the _meta.label field with the language name
  3. Translate all string values (keep the keys the same)
  4. 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.json

src/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:

PlaceholderDescription
{prefix}Bot command prefix
{error}Error message
{duration}Time duration
{command}Command name

Built with ❤️