Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 1.89 KB

File metadata and controls

62 lines (42 loc) · 1.89 KB

Localization (i18n)

OmegaBot uses i18n in src/i18n/index.ts for rate limits and errors. Cooldown messages respect guild locale (en/es/de).

Table of Contents


Current Status

  • English (en) – Default locale; all keys have translations
  • Spanish (es) – Common strings translated
  • German (de) – Common strings translated

Usage

import { t, resolveLocale } from "../i18n/index.js";

// Simple lookup (uses default locale)
const msg = t("rate_limit.try_again", "en", { seconds: 5 });
// → "Try again in 5s"

// With guild locale (e.g. from interaction.guild?.preferredLocale)
const locale = resolveLocale(interaction.guild?.preferredLocale);
const msg2 = t("error.generic", locale);

Adding Translations

  1. Add the key to translations.en in src/i18n/index.ts
  2. Add translations for es and de (or leave empty to fall back to English)
  3. Use t(key, locale, vars) in your code for variable substitution

Variable Substitution

Keys can use {variableName} placeholders:

"rate_limit.try_again": "Try again in {seconds}s"
t("rate_limit.try_again", "en", { seconds: 10 })  // → "Try again in 10s"

Extending Locales

To add a new locale (e.g. French):

  1. Add "fr" to the Locale type
  2. Add fr: { ... } to the translations object
  3. Update resolveLocale() to support guild/user locale preference (e.g. from guild_config or Discord's locale)

Wired Into Commands

  • Rate limits: formatCooldownMessage() uses t("rate_limit.cooldown_full", locale) with interaction.guild?.preferredLocale
  • Generic errors: Interaction handler uses t("error.generic", resolveLocale(guildLocale)) on command failure