Skip to content

Translating commands

Show your slash command and context menu names, descriptions, and choices in each user's Discord language without editing the command files.

Discord shows a command in the user's language if the command has localizations (opens in a new tab) for it. With discord.js builders, you'd set localizations on every command, option, and choice, so each command file would hold a block for every language.

The i18n plugin keeps those localizations out of your command files. You write one file per language. The plugin's prepareCommands adds them to your commands before seedcord sends them to Discord. The plugin reads these files from its path, so attach the plugin first, the way the i18n page shows.

Writing a translation file

Put a .ts file for each language in the plugin's path, in the same folder as the .ftl files. Use a Discord locale code (opens in a new tab) as its name:

src/locales
en-US.ftl
hi.ftl
hi.ts

Warning

The plugin treats every code file directly in path as a translation file, like .ts or .js. A helper file there fails with PluginI18nNotALocale, so keep your other code somewhere else.

Translation files are TypeScript so that TypeScript can check every key against your commands. The default export has to be a commandTranslations call. Anything else throws PluginI18nNotTranslations.

src/locales/hi.tshover for typestap for types, arrow keys walk the tokens
import { 
function commandTranslations(
    translations: CommandTranslations
): CommandTranslationFile
commandTranslations
} from '@seedcord/plugin-i18n';
export default
function commandTranslations(
    translations: CommandTranslations
): CommandTranslationFile
commandTranslations
({
CommandTranslations.slash?: {
    readonly ping?: {
        readonly name?: string;
        readonly description?: string;
        readonly options?: {
            readonly detailed?: {
                readonly name?: string;
                readonly description?: string;
            };
        };
    };
    readonly ban?: {
        readonly name?: string;
        readonly description?: string;
        readonly options?: {
            readonly target?: {
                readonly name?: string;
                readonly description?: string;
            };
            readonly reason?: {
                readonly name?: string;
                readonly description?: string;
            };
        };
    };
    readonly kick?: {
        readonly name?: string;
        readonly description?: string;
        readonly options?: {
            readonly target?: {
                readonly name?: string;
                readonly description?: string;
            };
        };
    };
    ... 14 more ...;
    readonly settings?: {
        ...;
    };
}
slash
: {
inventory?: {
    readonly name?: string;
    readonly description?: string;
    readonly options?: {
        readonly sort?: {
            readonly name?: string;
            readonly description?: string;
            readonly choices?: Readonly<Partial<Record<"newest" | "oldest", string>>>;
        };
    };
}
inventory
: {
name?: stringname: 'सामान', description?: stringdescription: 'अपना सामान देखें',
options?: {
    readonly sort?: {
        readonly name?: string;
        readonly description?: string;
        readonly choices?: Readonly<Partial<Record<"newest" | "oldest", string>>>;
    };
}
options
: {
sort?: {
    readonly name?: string;
    readonly description?: string;
    readonly choices?: Readonly<Partial<Record<"newest" | "oldest", string>>>;
}
sort
: {
name?: stringname: 'क्रम', description?: stringdescription: 'सामान किस क्रम में दिखे', choices?: Readonly<Partial<Record<"newest" | "oldest", string>>>choices: { newest?: stringnewest: 'सबसे नया', oldest?: stringoldest: 'सबसे पुराना' } } } },
settings?: {
    readonly name?: string;
    readonly description?: string;
    readonly subcommands?: {
        readonly language?: {
            readonly name?: string;
            readonly description?: string;
            readonly options?: {
                readonly language?: {
                    readonly name?: string;
                    readonly description?: string;
                };
            };
        };
        readonly reset?: {
            readonly name?: string;
            readonly description?: string;
        };
        readonly notifications?: {
            readonly name?: string;
            readonly description?: string;
            readonly subcommands?: {
                readonly enable?: {
                    readonly name?: string;
                    readonly description?: string;
                };
            };
        };
    };
}
settings
: {
name?: stringname: 'सेटिंग्स',
subcommands?: {
    readonly language?: {
        readonly name?: string;
        readonly description?: string;
        readonly options?: {
            readonly language?: {
                readonly name?: string;
                readonly description?: string;
            };
        };
    };
    readonly reset?: {
        readonly name?: string;
        readonly description?: string;
    };
    readonly notifications?: {
        readonly name?: string;
        readonly description?: string;
        readonly subcommands?: {
            readonly enable?: {
                readonly name?: string;
                readonly description?: string;
            };
        };
    };
}
subcommands
: {
language?: {
    readonly name?: string;
    readonly description?: string;
    readonly options?: {
        readonly language?: {
            readonly name?: string;
            readonly description?: string;
        };
    };
}
language
: {
name?: stringname: 'भाषा', description?: stringdescription: 'बॉट की भाषा चुनें' } } } },
CommandTranslations.userMenus?: {
    readonly 'View Profile'?: string;
    readonly Warn?: string;
}
userMenus
: { 'View Profile': 'प्रोफ़ाइल देखें' },
CommandTranslations.messageMenus?: {
    readonly 'Report Message'?: string;
}
messageMenus
: { 'Report Message': 'मैसेज रिपोर्ट करें' }
});

The keys under slash, options, subcommands, and the two menu sections are the ones from your code, like inventory, sort, and 'View Profile'. Users whose Discord language is Hindi see /सामान in the command picker, and प्रोफ़ाइल देखें when they right-click a member.

keytakes
a command under slashname, description, options, and subcommands
an option under optionsname, description, and choices
a subcommand or a subcommand group under subcommandsname, description, options, and subcommands for a group's own subcommands
a menu under userMenus or messageMenusits translated name as a string

The keys of choices are the choice values, like newest, because your code gets the same value back in every language. A number value is written as a string, like '5'.

Every field is optional. If you leave a field out, Discord shows the text from your code, so settings in the sample keeps its English description.

The keys come from your commands

seedcord codegen writes your commands, their options and choices, and your context menus into seedcord-gen.ts. commandTranslations gets its types from that file, so run codegen after you add or rename a command. Then your editor shows what each key can be, like the values of a choice:

export default commandTranslations({
    slash: {
        inventory: {
            options: { sort: { choices: { '
  • newest
  • oldest

If you rename a command or an option and run codegen, every translation file that still uses the old name fails to compile:

export default commandTranslations({
    slash: {
        inventory: {
            options: { order: { name: 'क्रम' } }
Object literal may only specify known properties, and 'order' does not exist in type '{ readonly sort?: { readonly name?: string; readonly description?: string; readonly choices?: Readonly<Partial<Record<"newest" | "oldest", string>>>; }; }'.
} } });

order isn't an option of inventory, so TypeScript reports it. If you haven't run codegen since the rename, TypeScript misses it. The plugin still finds it before the deploy and throws PluginI18nUnknownCommand.

When the plugin applies them

The plugin adds the translations every time seedcord reads your commands:

  • when a bot starts and deploys its commands, which includes a Workers bot under seedcord dev
  • when you answer y to the Refresh commands? prompt in seedcord dev
  • in seedcord commands deploy and seedcord commands list
  • in seedcord build for Cloudflare Workers
  • in seedcord codegen, which only checks the files

A broken translation file stops each of these. Saving a translation file in seedcord dev shows the same refresh prompt as saving a command file.

A deployed Worker never deploys its own commands. To send new translations to Discord for a Worker, run seedcord commands deploy before you build.

A new translation changes the command in Discord, so the next deploy sends that command even if its file didn't change. seedcord only skips a scope, like the global commands or one server's commands, when nothing in it changed.

What Discord accepts

Discord rejects a whole deploy if one translation breaks its naming rules (opens in a new tab). The plugin checks each translation against these rules before anything reaches Discord:

fieldDiscord accepts
a slash command, subcommand, or option name1 to 32 characters of letters, numbers, -, _, or ', without spaces. Letters have to be lowercase in a script that has case. Hindi's script doesn't have case
a description1 to 100 characters
a choice's name1 to 100 characters
a userMenus or messageMenus name1 to 32 characters. Capitals and spaces are fine

If a translation breaks one of these rules, the plugin throws PluginI18nDiscordRejects. The message gives the file, the path to the field inside it, the value, and the rule:

src/locales/hi.ts sets slash.inventory.name to "मेरा सामान", but Discord only accepts a name of 1 to 32 lowercase letters, numbers, -, _ or ', without spaces. Change the translation to fit.

Errors

errorwhen
PluginI18nNotALocalea code file in path doesn't have a Discord locale code as its name
PluginI18nNotTranslationsa translation file's default export isn't the result of commandTranslations
PluginI18nUnknownCommanda translation file has a command, option, subcommand, choice, or menu that your commands don't
PluginI18nDiscordRejectsa translation breaks one of Discord's naming rules
PluginI18nCommandProblemsthe files have two or more of the problems above. Each one is in the error's errors

The plugin checks every translation file before it throws, and reports every problem it finds in one error. Fix them and run codegen again, or press g in seedcord dev.