feat(i18n): resolve Species/Breed display names via SpeciesTranslation/BreedTranslation

User found "Cat" showing English on a German-locale profile page. Root
cause: Species.name/Breed.name are the canonical English values; a
SpeciesTranslation/BreedTranslation table + seed data (Hund/Katze/Vogel
etc.) already existed in the schema, and PetForm's species/breed picker
already used it correctly via an explicit locale input param — but every
*display* surface (pet profile, PetCard, Sidebar/MobileNav, search,
explore, followers/following lists, mention @-search, health-card) just
read the raw untranslated name.

Adds `locale` to the tRPC context (createTRPCContext reads the
NEXT_LOCALE cookie the same way i18n/request.ts does), so read
procedures can resolve translations without every caller needing to
pass a locale param. New src/lib/localized-name.ts::pickLocalizedName()
does the lookup with a same-shape fallback to the raw name.

Updated: pets.ts (list/byId/getProfile/update), search.ts (pets/byOwner),
explore.ts (listPets), follows.ts (listFollowers/listFollowing).
health-card/[token]/page.tsx (public, unauthenticated, intentionally
all-German) resolves with a fixed "de" locale instead of ctx.locale,
consistent with its existing hardcoded WeightChart locale.

Verified the seed data is actually present in the production DB
(SpeciesTranslation has Dog→Hund, Cat→Katze, Bird→Vogel) — this fix is
immediately effective on deploy, not blocked on a missing seed run.
This commit is contained in:
admin committed 2026-07-23 15:19:55 +02:00
1 parent b7719397e6
commit 25fa2a3bec
10 files changed
+138 -30

No files matched your search

+2
View File
@@ -79,10 +79,12 @@ function createTestCaller(
type CallerCtx = {
userId: string | null;
prisma: import("@prisma/client").PrismaClient;
locale: string;
};
const ctx: CallerCtx = {
userId,
prisma: mockPrisma as unknown as import("@prisma/client").PrismaClient,
locale: "en",
};
return mediaRouter.createCaller(ctx);
}
+2 -1
View File
@@ -54,10 +54,11 @@ function createTestCaller(userId: string, mockPrisma: ReturnType<typeof createMo
// petsRouter.createCaller accepts the same context shape as createTRPCContext returns.
// Cast the mock to the expected PrismaClient type — mock has the same interface for
// tested methods.
type CallerCtx = { userId: string | null; prisma: import("@prisma/client").PrismaClient };
type CallerCtx = { userId: string | null; prisma: import("@prisma/client").PrismaClient; locale: string };
const ctx: CallerCtx = {
userId,
prisma: mockPrisma as unknown as import("@prisma/client").PrismaClient,
locale: "en",
};
return petsRouter.createCaller(ctx);
}