Package
plugin-i18n v0.1.0

About
@seedcord/plugin-i18n translates your bot's replies and commands into each user's Discord language. You write the replies in Fluent files, one per locale, and format them in any handler with this.t.
It works with a gateway bot, with an http bot on your own server, and with an http bot on Cloudflare Workers.
seedcord is in beta, so a minor version can break your bot. Each release's changelog says what changed and how to update.
Installation
pnpm add @seedcord/plugin-i18nUsage
Attach the plugin in bot.ts, and list its folder under files in seedcord.config.ts:
// src/bot.ts
import { Seedcord } from '@seedcord/http';
import { I18n } from '@seedcord/plugin-i18n';
export default new Seedcord({
bot: {
interactions: { path: './handlers' },
commands: { path: './commands' }
},
subscribers: { path: null }
}).attach('i18n', I18n, { path: './locales', base: 'en-US' });// seedcord.config.ts
import { defineConfig } from 'seedcord';
export default defineConfig({
root: './src',
files: ['./locales']
});Put every message in the base file. Give each other locale a file with its Discord locale code as the name, like hi.ftl:
# src/locales/en-US.ftl
items =
{ $count ->
[one] You have { $count } item
*[other] You have { $count } items
}After seedcord codegen, this.t only accepts the keys and variables in the base file:
await this.reply(this.t('items', { count: cart.length }));The i18n guide covers the Fluent files, which language t picks, and t in gates, notices, and components. Translating commands shows how to translate your command names and descriptions.