CIRCE / DOCUMENTATION
Localization
Translate replies per user or per server across all 32 Discord locales, with a working resolver.
On this page
The resolver
Export a resolver from src/localization.ts (the older i18n.ts name still works). Circe connects it to ctx.t(key, params) in every handler.
// src/localization.ts
import { defineLocalizationResolver, interpolate } from "@sxnnyside/circe";
const translations: Record<string, Record<string, string>> = {
"en-US": { "ping.reply": "🏓 Pong! Latency: {latency}ms" },
es: { "ping.reply": "🏓 ¡Pong! Latencia: {latency}ms" },
};
export default defineLocalizationResolver({
resolve(key, locale, params, context) {
// context: { guildId, guildLocale, userId }
const lang = locale.startsWith("es") ? "es" : "en-US";
const template = translations[lang]?.[key] ?? translations["en-US"]?.[key] ?? key;
return interpolate(template, params);
},
});
Use it anywhere:
await interaction.reply(ctx.t("ping.reply", { latency: 42 }));
locale is the invoking user’s Discord locale. The fourth argument, LocalizationContext, lets you resolve per server (guildLocale) or per user (userId, for a saved preference) instead of only per Discord client. Always fall back to a default language, as above.
Helpers
| Export | Purpose |
|---|---|
DiscordLocale |
Union of all 32 official locales, with a dialect-string fallback. |
localizationContextOf |
Builds the context from an interaction. |
createTranslator |
Binds a resolver to a locale outside a handler. |
resolveInteractionLocale |
Experimental. User-versus-guild priority with fallback chains. |
interpolate |
Experimental. Zero-dependency {token} replacement. |
Localized command metadata
Discord shows command names and descriptions in the user’s language when you provide localization maps. Use discord.js’s setNameLocalizations on the builder, nameLocalizations and descriptionLocalizations in a group’s _group.ts, and nameLocalizations on context menus.
