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:
1 parent
b7719397e6
commit
25fa2a3bec
10 files changed
+138
-30
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import "server-only";
|
||||
|
||||
interface NameTranslation {
|
||||
locale: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a translated display name from a SpeciesTranslation/BreedTranslation
|
||||
* row set, falling back to the canonical (English) `name` field when no
|
||||
* translation matches the requested locale (e.g. locale is "en", or the
|
||||
* translation just hasn't been seeded for that locale).
|
||||
*/
|
||||
export function pickLocalizedName(
|
||||
name: string,
|
||||
translations: NameTranslation[] | null | undefined,
|
||||
locale: string
|
||||
): string {
|
||||
return translations?.find((t) => t.locale === locale)?.name ?? name;
|
||||
}
|
||||
Reference in new issue
Block a user