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

+14 -14
View File
@@ -89,28 +89,28 @@ function getLivePlayerCount(playerMap) {
// ── Embed builder ─────────────────────────────────────────────────────────────
function buildEmbed({ guildCount, userCount, playerCount, ping, uptime, comHash, comLink, reason, footer, loading }) {
function buildEmbed(t, msg, { guildCount, userCount, playerCount, ping, uptime, comHash, comLink, reason, footer, loading }) {
const num = (v) => Utils.formatNumber(v);
const ld = (v) => loading ? "..." : v;
const description = [
`📂 **Servers** — \`${num(guildCount)}\``,
`👥 **Users** — \`${ld(num(userCount))}\``,
`🎧 **Players** — \`${num(playerCount)}\``,
`🏓 **Ping** — \`${ld(`${num(ping)}ms`)}\``,
`⏱️ **Uptime** — \`${uptime}\``,
`🔧 **Build** — [\`${comHash}\`](${comLink})`,
reason ? `🪛 **Last restart** — \`${reason}\`` : null,
`${t(msg, "responses.stats.servers")} — \`${num(guildCount)}\``,
`${t(msg, "responses.stats.users")} — \`${ld(num(userCount))}\``,
`${t(msg, "responses.stats.players")} — \`${num(playerCount)}\``,
`${t(msg, "responses.stats.ping")} — \`${ld(`${num(ping)}ms`)}\``,
`${t(msg, "responses.stats.uptime")} — \`${uptime}\``,
`${t(msg, "responses.stats.build")} — [\`${comHash}\`](${comLink})`,
reason ? `${t(msg, "responses.stats.lastRestart")} — \`${reason}\`` : null,
``,
`☕ [Support us on Ko-fi](https://ko-fi.com/remixbot)`,
`💬 [Community](https://fluxer.gg/Remix)`,
t(msg, "responses.stats.supportKofi"),
t(msg, "responses.stats.community"),
].filter(l => l !== null).join("\n");
const builder = new EmbedBuilder()
.setColor(getGlobalColor())
.setAuthor({ name: "Remix Music Bot" })
.setAuthor({ name: t(msg, "responses.stats.title") })
.setDescription(description)
.setFooter({ text: footer || "Remix Music Bot" });
.setFooter({ text: footer || t(msg, "responses.stats.title") });
if (typeof builder.setTimestamp === "function") builder.setTimestamp();
return builder;
@@ -134,13 +134,13 @@ export async function run(message) {
// Measure real round-trip latency
const start = Date.now();
const msg = await message.reply({
embeds: [buildEmbed({ ...shared, userCount: hasCached ? cachedUserCount : 0, ping: 0, loading: !hasCached })]
embeds: [buildEmbed((...a) => this.t(...a), message, { ...shared, userCount: hasCached ? cachedUserCount : 0, ping: 0, loading: !hasCached })]
});
const ping = Date.now() - start;
const users = await getUserCount(this.client);
await msg.edit({
embeds: [buildEmbed({ ...shared, userCount: users, ping, loading: false })]
embeds: [buildEmbed((...a) => this.t(...a), message, { ...shared, userCount: users, ping, loading: false })]
}).catch((err) => console.error("[stats] editEmbed failed:", err));
}