Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Ready bots and skins keep their English when the catalog lacks a key

milind-sonif6e8a0513fed
diff --git a/src/components/SkinPicker.tsx b/src/components/SkinPicker.tsx
index 9218061d3d..1cafdce653 100644
--- a/src/components/SkinPicker.tsx
+++ b/src/components/SkinPicker.tsx
@@ -3,8 +3,7 @@
import { Check } from "lucide-react";
import { SKINS, applySkin, resolveSkin, type SkinId } from "@/lib/skins";
import { cn } from "@/lib/cn";
-import { t } from "@/lib/i18n";
-import type { LocaleKey } from "@/locales";
+import { t, tFromServer } from "@/lib/i18n";
import { setDressUp, useDressUp } from "@/lib/halloween-dress";
import type { HalloweenBodyId } from "../../shared/halloween-bodies";
import { MausAvatar } from "./Avatar";
@@ -108,7 +107,7 @@ export function SkinPicker() {
<div className="min-w-0 flex-1">
<div className="text-[13px] font-medium text-ink">{skin.name}</div>
<div className="mt-0.5 text-[11px] leading-snug text-ink-secondary">
- {t(`skins.tagline.${skin.id}` as LocaleKey) || skin.tagline}
+ {tFromServer(`skins.tagline.${skin.id}`, skin.tagline)}
</div>
</div>
{selected && <Check size={13} className="mt-0.5 shrink-0 text-accent-text" />}
diff --git a/src/lib/ready-bots.test.ts b/src/lib/ready-bots.test.ts
index 0e6fd419ea..eadf13f2a3 100644
--- a/src/lib/ready-bots.test.ts
+++ b/src/lib/ready-bots.test.ts
@@ -1,7 +1,9 @@
import { describe, expect, it } from "vitest";
import { MAUS_COLORS } from "./mascot";
-import { CLASSIC_ROLE_IDS, READY_BOT_CATEGORIES, READY_BOTS, matchesReadyBot, readyBot, readyBotTemplate } from "./ready-bots";
+import { CLASSIC_ROLE_IDS, READY_BOT_CATEGORIES, READY_BOTS, matchesReadyBot, readyBot, readyBotCopy, readyBotTemplate } from "./ready-bots";
+import { setLocale } from "./i18n";
+import en from "@/locales/en.json";
import { MASCOT_BODY_IDS } from "../../shared/mascot-bodies";
import type { NewBotDefaults } from "../../shared/new-bot-defaults";
@@ -85,6 +87,20 @@ describe("matchesReadyBot", () => {
});
});
+describe("readyBotCopy", () => {
+ it("reads each bot's words from the catalog, and keeps a bot's own English when the catalog has none", () => {
+ for (const bot of READY_BOTS) for (const field of ["title", "description", "try"]) expect(Object.hasOwn(en, `readyBots.bot.${bot.id}.${field}`), `${bot.id}.${field}`).toBe(true);
+ const unlisted = { ...readyBot("humanizer")!, id: "not-in-the-catalog", title: "Its title", description: "Its words", tryAsking: ["Its ask"] };
+ try {
+ setLocale("pt-br");
+ expect(readyBotCopy(unlisted)).toEqual({ title: "Its title", description: "Its words", tryAsking: "Its ask" });
+ expect(readyBotCopy(readyBot("humanizer")!).title).not.toBe(readyBot("humanizer")!.title);
+ } finally {
+ setLocale("en");
+ }
+ });
+});
+
describe("the social media manager", () => {
const social = readyBot("social")!;
diff --git a/src/lib/ready-bots.ts b/src/lib/ready-bots.ts
index 93fcf96b74..37f00a2cfa 100644
--- a/src/lib/ready-bots.ts
+++ b/src/lib/ready-bots.ts
@@ -1,8 +1,7 @@
import type { BotRoutineTemplate, NewBotDefaults } from "../../shared/new-bot-defaults";
import type { MascotBodyId } from "../../shared/mascot-bodies";
import type { MausColor } from "../../shared/wire";
-import { t } from "@/lib/i18n";
-import type { LocaleKey } from "@/locales";
+import { t, tFromServer } from "@/lib/i18n";
export type ReadyBotCategory = "everyday" | "work" | "writing" | "design" | "sales" | "personal";
@@ -351,7 +350,7 @@ export function readyBotTemplate(defaults: NewBotDefaults, bot: ReadyBot): NewBo
}
export function readyBotCopy(bot: ReadyBot): { title: string; description: string; tryAsking: string } {
- const copy = (field: string, english: string) => t(`readyBots.bot.${bot.id}.${field}` as LocaleKey) || english;
+ const copy = (field: string, english: string) => tFromServer(`readyBots.bot.${bot.id}.${field}`, english);
return { title: copy("title", bot.title), description: copy("description", bot.description), tryAsking: copy("try", bot.tryAsking[0]!) };
}
diff --git a/src/lib/skins.test.ts b/src/lib/skins.test.ts
index 9ea5987f52..cfbd7af5fa 100644
--- a/src/lib/skins.test.ts
+++ b/src/lib/skins.test.ts
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { describe, expect, it } from "vitest";
import { SKINS, SKIN_IDS, DEFAULT_SKIN_CHOICE, PRIOR_INSTALL_SKIN, THEME_SKINS, resolveSkin } from "./skins";
+import en from "@/locales/en.json";
const css = readFileSync(
join(dirname(fileURLToPath(import.meta.url)), "../styles.css"),
@@ -18,6 +19,10 @@ describe("skins", () => {
for (const id of SKIN_IDS) expect(blocks).toContain(id);
});
+ it("gives every skin a tagline in the catalog", () => {
+ expect(SKINS.map((skin) => `skins.tagline.${skin.id}`).filter((key) => !Object.hasOwn(en, key))).toEqual([]);
+ });
+
it("registers every stylesheet block", () => {
for (const id of blocks) expect(SKIN_IDS).toContain(id as (typeof SKIN_IDS)[number]);
});