Translations (bot + dashboard)
Phantom speaks 14 languages: English, French, Spanish, German, Romanian, Polish, Dutch, Chinese (Simplified), Arabic, Japanese, Korean, Russian, Portuguese (Brazil) and Hindi.
- Bot language is per server: Guild Settings → Bot language (
guild_settings.language). Every reply, embed, button, select menu, modal, autocomplete choice and DM the bot sends for that server goes out in that language, including tenant (custom-branded) bots and sidecar posts (streamer alerts, scheduled messages, trivia, birthdays). Slash-command descriptions are also registered with Discord's native localizations, which follow each member's own Discord app language. Discord has no Arabic client locale, so in the slash-command picker Arabic falls back to English. Replies are still in Arabic. - Dashboard language is per account: the language picker in the sidebar, on the account page and on the server picker (
users.locale; signed-out visitors get a cookie, otherwise the browser'sAccept-Language). Arabic switches the page to right-to-left.
How it works
Call sites keep writing plain English. Translation happens on the way out, against a catalog keyed by the English text:
| Surface | Where | What it translates |
|---|---|---|
| Bot | bot/src/i18n/interceptor.js wraps rest.request | message/interaction/webhook/modal/autocomplete payloads, per target server |
| Bot images | bot/src/levelling/rank-card.js | labels drawn into the rank card PNG |
| Slash commands | bot/src/commands/builder.js | description_localizations, choice name_localizations |
| Dashboard HTML/JSON | app/Http/Middleware/Localize.php | rendered pages, JSON toasts/errors/HTML fragments |
| Dashboard browser | resources/js/i18n.js | text inserted after load, alert/confirm/prompt |
Interpolated text is matched as a pattern: `Banned ${user} for ${reason}` is stored as Banned {0} for {1} and its captured values are translated recursively. Text with no catalog match (user content, server names) passes through unchanged. Every layer fails open: a translation error sends the English original.
Files
bot/src/i18n/source.json: bot strings, extracted from the codelang/source/dashboard.json: dashboard strings, extracted from the views/configlang/source/extra.json: hand-added strings (switcher UI, Laravel validation)lang/translations/<lang>.json: the translations (English → target). Edit these.- Generated, do not edit:
bot/src/i18n/locales/<lang>.json,lang/compiled/<lang>.php,public/i18n/<lang>.json
After changing user-facing text
npm install # acorn / acorn-walk (root devDependencies)
node scripts/i18n/extract-bot.cjs # refresh bot/src/i18n/source.json
node scripts/i18n/extract-dashboard.cjs # refresh lang/source/dashboard.json
node scripts/i18n/missing.cjs fr # list strings fr has no translation for
# add translations to lang/translations/<lang>.json, then:
node scripts/i18n/build.cjs # regenerate the runtime filesNew strings that nobody has translated yet simply show in English until they are added, so nothing breaks in the meantime.
Rules for translations: keep {0}-style placeholders, {user}-style template variables, Discord markdown, mentions (<@{0}>), slash commands, URLs and brand names (Phantom, Discord, Twitch, …) exactly as in the source.
Marketing site (SEO)
/languages: English hub for English searches ("French Discord moderation bot", "multilingual Discord bot"), with a section per language./fr,/es,/de, …: one landing page per language, written natively for local searches. Copy lives inlang/marketing/<code>.json(en.jsonis the template and fallback).{price_monthly}/{price_yearly}are filled fromconfig/premium.php.- The home page and the landing pages form one hreflang cluster (rendered by
partials/marketing/_hreflang, and withxhtml:linkalternates in/sitemap.xml).x-defaultis the home page. - Structured data declares every supported language (
inLanguageon the SoftwareApplication)./llms.txtgives AI crawlers a plain-text summary, generated from the same config.robots.txtnames the major AI crawlers. - Adding a language: add it to
Languages::ALLand the route constraint inroutes/web.php, writelang/marketing/<code>.json, and add the flag SVG. - Header and footer on the language pages: the partials stay English; the layout translates their rendered HTML from
lang/marketing/nav/<code>.json(App\Support\I18n\MarketingNav). After changing header/footer text, runphp scripts/i18n/extract-marketing-nav.phpto refreshlang/marketing/nav/source.json, then add the new strings to each language file (missing ones simply show in English). Text that JavaScript inserts must come from markup (see the hidden status-pill labels).
Trivia
Trivia questions are localized separately from the string catalog, because they're data (names, answers, word lists) rather than UI text.
bot/src/trivia/i18n/<lang>.jsonholds, per language: the prompt templates, the localized names of every country, city, continent, currency and landmark, the translated general-knowledge questions with their answers, and a native word list for unscramble (empty for zh, ja and hi, where unscramble steps aside).node scripts/i18n/extract-trivia.cjsrebuildssource.jsonfrombot/src/trivia/data/; translate what changed into each language file (or intoparts/<lang>.geo.json/parts/<lang>.general.jsonand runnode scripts/i18n/merge-trivia.cjs).bot/tests/trivia-i18n.test.jsfails if a language is missing anything.- A localized question accepts the local answers and the English ones.
- Answer matching is Unicode-aware.
bot/src/trivia/answer-fold.json(built byscripts/i18n/build-answer-fold.cjs) is shared by the bot'sanswer-matcher.jsand the dashboard'sTriviaController::normaliseAnswer(), andbot/tests/fixtures/trivia-normalise.jsonis asserted on both sides. - Shared-bank multiple-choice rows get a
translationscolumn filled by the sidecar's top-up job. A non-English guild only draws rows already translated into its language. Flags are localized via the pack. Custom questions are served exactly as the guild wrote them.
