feat: add i18n locale system and fix pagination/help bugs

- Add Locale class (src/constants/Locale.mjs) with per-guild translation
  support and settings-manager binding
- Wire locale into CommandHandler, MessageHandler, Player, PlayerManager,
  and index.mjs via setLocale() / t() helpers
- Replace all hardcoded English strings (help pages, errors, now-playing,
  permission messages, session-closed footers) with locale key lookups
- Fix: %help triggering "Unknown command" — replyHandler intercept now
  uses case-insensitive check for "unknown command"
- Fix: TypeError crash in closeSession when embed has no footer — guard
  with `if (!footer) footer = { text: "" }` before appending
- Fix: media player teardown now calls destroy() and nulls the instance
  instead of relying on _stopMediaPlayer(), preventing stale state
- Refactor: reply() and send() auto-wrap plain strings in embeds,
  matching old replyEmbed/sendEmbed behaviour
- Refactor: permission errors and invalid-flag errors use t() lookups
- Add top-level t(message, key, data) helper on the bot instance for
  command files to resolve guild locale without manual guildId plumbing
This commit is contained in:
NoLogicAlan committed 2026-05-06 01:07:03 +03:00
1 parent 1ff1f9d78f
commit 6060e6d318
36 files changed
+2752 -689

No files matched your search

+26
View File
@@ -12,6 +12,7 @@ import { getVoiceManager } from "@fluxerjs/voice";
import { MoonlinkManager } from "./src/MoonlinkManager.mjs";
import mysql from "mysql";
import { Dashboard } from "./src/dashboard/Dashboard.mjs";
import { Locale } from "./src/constants/Locale.mjs";
export class Remix {
constructor() {
@@ -38,6 +39,10 @@ export class Remix {
// Apply embed color from config globally
setGlobalColor(config.embedColor);
// ── Locale (i18n) ────────────────────────────────────────────────────────
this.locale = new Locale();
this.locale.load();
this.dashboard = new Dashboard(this, {
mysql: config.mysql,
...config.dashboard,
@@ -81,10 +86,15 @@ export class Remix {
const settings = new RemoteSettingsManager(config.mysql, "./storage/defaults.json");
this.settingsMgr = settings;
// Bind settings manager to locale so it can resolve per-guild locale settings
this.locale.bind(this.settingsMgr);
const commands = new CommandHandler(messages);
this.handler = commands;
commands.setPrefixManager(new PrefixManager(settings));
commands.setLocale(this.locale);
messages.setLocale(this.locale);
// ── Help command ──────────────────────────────────────────────────────────
new HelpCommand(commands, messages, (msg) => this.getSettings(msg)).register();
@@ -1250,6 +1260,7 @@ export class Remix {
config,
player: this.playerContext,
dashboard: this.dashboard,
locale: this.locale,
});
this.players.observedVoiceUsers = this.observedVoiceUsers;
@@ -1516,6 +1527,21 @@ export class Remix {
return this.settingsMgr.getServer(guildId);
}
/**
* Translate a key for the guild of the given message.
* @param {Message} message
* @param {string} key Dotted locale key, e.g. "responses.play.noResults"
* @param {Object} [data={}] Replacement values, e.g. { count: 5 }
* @returns {string}
*/
t(message, key, data = {}) {
const guildId = message?.channel?.channel?.guildId
?? message?.message?.guildId
?? message?.guildId
?? null;
return this.locale.translate(guildId, key, data);
}
getPlayer(message, promptJoin, verifyUser, shouldJoin) {
return this.players.getPlayer(message, promptJoin, verifyUser, shouldJoin);
}