Skip to main content

pycord-localizer

PyPI version downloads Python versions License: MIT

A pycord extension for internationalization and localization.

Installation

# linux / macOS
pip3 install pycord-localizer

# windows
pip install pycord-localizer

Quick Start

1. Create a Locales Folder

Instead of one file per language, organize translations by feature/domain. Each file holds every locale it needs, keyed by category first (strings, commands, context_menus) and locale second:

locales/
    info.json
    music.json
    roles.json

locales/info.json

{
    "strings": {
        "zh-TW": {
            "Hello, world!": "你好,世界!"
        },
        "zh-CN": {
            "Hello, world!": "你好,世界!"
        }
    },
    "commands": {
        "greet": {
            "zh-TW": {
                "name": "問候",
                "description": "向使用者問候",
                "options": {
                    "user": {
                        "name": "使用者",
                        "description": "選擇要問候的使用者"
                    }
                }
            }
        }
    },
    "context_menus": {
        "user_info": {
            "zh-TW": {
                "name": "使用者資訊"
            }
        }
    }
}

Files are merged together, so multiple files may contribute strings, commands, or context menus for the same locale.

2. Setup in Your Bot

from discord import Bot, Option
from pycord_localizer import I18n, t

# Create bot and load every file under locales/
bot = Bot()
i18n = I18n(bot, locales_dir="locales")

# Define commands
@i18n.localize
@bot.slash_command()
async def greet(ctx, user: Option(discord.Member, "Select a user")):
    await ctx.respond(t("Hello, {0}!", user.mention))

bot.run("YOUR_TOKEN")

Alternative: One File per Locale

The original per-locale file format is still supported, either loaded manually or merged in alongside locales_dir:

import json
from pycord_localizer import I18n

with open("zh-TW.json", encoding="utf-8") as f:
    zh_tw = json.load(f)

i18n = I18n(bot, zh_TW=zh_tw)
// zh-TW.json
{
    "strings": {
        "Hello, world!": "你好,世界!"
    },
    "commands": {
        "greet": {
            "name": "問候",
            "description": "向使用者問候"
        }
    }
}

Documentation

Supported 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"

Localization Structure

Locales folder format (category first, locale second — for locales_dir):

{
    "strings": {
        "locale_code": {
            "key": "translated text",
            "format {0}": "格式化 {0}"
        }
    },
    "commands": {
        "command_name": {
            "locale_code": {
                "name": "localized_name",
                "description": "localized_description",
                "options": {
                    "option_name": {
                        "name": "localized_option",
                        "description": "localized_description",
                        "choices": {
                            "choice_value": "localized_choice_name"
                        }
                    }
                }
            }
        }
    },
    "context_menus": {
        "context_menu_name": {
            "locale_code": {
                "name": "localized_menu_name"
            }
        }
    }
}

Single-locale file format (for files loaded manually and passed as **translations):

{
    "strings": {
        "key": "translated text",
        "format {0}": "格式化 {0}"
    },
    "commands": {
        "command_name": {
            "name": "localized_name",
            "description": "localized_description",
            "options": {
                "option_name": {
                    "name": "localized_option",
                    "description": "localized_description",
                    "choices": {
                        "choice_value": "localized_choice_name"
                    }
                }
            }
        }
    },
    "context_menus": {
        "context_menu_name": {
            "name": "localized_menu_name"
        }
    }
}

Examples

Slash Command with Choices

from discord import Option, OptionChoice

@i18n.localize
@bot.slash_command()
async def language(
    ctx,
    lang: Option(
        str,
        "Choose your preferred language",
        choices=[
            OptionChoice(name="English", value="en-US"),
            OptionChoice(name="Traditional Chinese", value="zh-TW"),
            OptionChoice(name="Japanese", value="ja"),
            OptionChoice(name="German", value="de"),
        ]
    )
):
    await ctx.respond(f"Language set to: {lang}")

Localization file:

{
    "commands": {
        "language": {
            "name": "語言",
            "description": "選擇你的偏好語言",
            "options": {
                "lang": {
                    "name": "語言",
                    "description": "選擇你偏好的語言",
                    "choices": {
                        "en-US": "英文",
                        "zh-TW": "繁體中文",
                        "ja": "日文",
                        "de": "德文"
                    }
                }
            }
        }
    }
}

Context Menu Commands

# User command (right-click on user)
@i18n.localize
@bot.user_command(name="user_info")
async def user_info(ctx, member):
    await ctx.respond(_("User: {0}", member.name))

# Message command (right-click on message)
@i18n.localize
@bot.message_command(name="get_id")
async def get_id(ctx, message):
    await ctx.respond(_("Message ID: {0}", message.id))

Batch Localization

Instead of decorating each command, you can localize all at once:

# Define all commands first
@bot.slash_command()
async def hello(ctx):
    await ctx.respond(_("Hello!"))

@bot.user_command(name="user_info")
async def user_info(ctx, member):
    await ctx.respond(f"User: {member.name}")

# Then localize all commands
i18n.localize_commands()

String Formatting

# Simple formatting
await ctx.respond(_("Hello, {0}!", user.name))

# Multiple arguments
await ctx.respond(_("User {0} has {1} points", name, points))

User vs Server Locale

# Default: Use server locale
i18n = I18n(bot, zh_TW=zh_tw)

# Use user's preferred locale
i18n = I18n(bot, consider_user_locale=True, zh_TW=zh_tw)

Metadata

Release files for pycord-localizer 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycord-localizer 0.2.0
File Size Uploaded Provenance Actions
pycord_localizer-0.2.0.tar.gz 14.5 kB With provenance Details for pycord_localizer-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pycord-localizer 0.2.0
File Interpreter ABI Platform Actions
pycord_localizer-0.2.0-py3-none-any.whl Python 3 none any Details for pycord_localizer-0.2.0-py3-none-any.whl

Total release size: 27.9 kB

Release files / pycord_localizer-0.2.0.tar.gz

Download URL pycord_localizer-0.2.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f5a7ddcccd879b097a08fe42826816a3a039134142c1d754e8b9297968933b36
BLAKE2b-256 checksum
How to use checksums
a10c7b12d03f56ca901f3cf28cef543929f4f3932fadc3ce222c9c951d0fda46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release files / pycord_localizer-0.2.0-py3-none-any.whl

Download URL pycord_localizer-0.2.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
179c76ee09a57d6312578727dfa6bb56ee45547ff127ddc57b982ab917a376c1
BLAKE2b-256 checksum
How to use checksums
83e0c59723561f779db83a20ec3c32ffbde3b713df0188532d2f7917700385b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Security for pycord-localizer 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pycord_localizer-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page