Skip to main content
Version: Next

i18n Plugin

The i18n plugin integrates i18next into CommandKit, enabling you to create multilingual Discord bots that can automatically adapt to your users' preferred languages. This plugin provides seamless internationalization support for commands, events, and all bot interactions.

Features​

  • 🌍 Automatic locale detection - Automatically uses Discord's guild preferred locale
  • πŸ”§ Easy setup - Simple configuration with sensible defaults
  • πŸ“ File-based translations - Organize translations in JSON files
  • 🎯 Context-aware - Access translations in commands, events, and legacy handlers
  • πŸ”Œ i18next ecosystem - Full compatibility with i18next plugins and features
  • πŸ“ Command metadata localization - Localize command names, descriptions, and options

Installation​

npm install @commandkit/i18n

Basic Setup​

Add the i18n plugin to your CommandKit configuration:

import { defineConfig } from 'commandkit';
import { i18n } from '@commandkit/i18n';

export default defineConfig({
plugins: [i18n()],
});

Advanced Configuration​

You can customize the i18n plugin by passing options to it:

import { defineConfig } from 'commandkit';
import { i18n } from '@commandkit/i18n';

export default defineConfig({
plugins: [
i18n({
plugins: [someI18nextPlugin],
// Add other i18next configuration options as needed
}),
],
});

Translation Files Structure​

Create a locales directory inside your src/app folder with subdirectories for each language. Each language directory should contain JSON files for your translations.

src
└── app
β”œβ”€β”€ locales
β”‚ β”œβ”€β”€ en-US
β”‚ β”‚ └── ping.json
β”‚ β”‚ └── messageCreate.event.json
β”‚ └── fr
β”‚ └── ping.json
β”‚ └── messageCreate.event.json
β”œβ”€β”€ commands
β”‚ β”œβ”€β”€ ping.ts
β”‚ └── help.ts
└── events
└── messageCreate
└── handler.ts

Supported Locales​

CommandKit uses Discord's locale identifiers. Please refer to Discord's Locales documentation for a complete list.

Quick Start Example​

Here's a complete example to get you started:

  1. Configure the plugin:
commandkit.config.ts
import { defineConfig } from 'commandkit';
import { i18n } from '@commandkit/i18n';

export default defineConfig({
plugins: [i18n()],
});
  1. Create translation files:
src/app/locales/en-US/ping.json
{
"$command": {
"name": "ping",
"description": "Check the bot's latency"
},
"response": "πŸ“ Pong! Latency: **{{latency}}ms**"
}
src/app/locales/fr/ping.json
{
"$command": {
"name": "ping",
"description": "VΓ©rifier la latence du bot"
},
"response": "πŸ“ Pong! Latence: **{{latency}}ms**"
}
  1. Use translations in your command:
src/app/commands/ping.ts
import type { ChatInputCommand, CommandData } from 'commandkit';

export const command: CommandData = {
name: 'ping',
description: "Check the bot's latency",
};

export const chatInput: ChatInputCommand = async (ctx) => {
const { t } = ctx.locale();

await ctx.interaction.reply({
content: t('response', { latency: ctx.client.ws.ping }),
});
};

That's it! Your bot will now automatically respond in the user's guild preferred language.