From 192221eafcc53aa7fc07d88f1cd8ebba6bae30df Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Fri, 24 Apr 2026 08:56:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=9A=E8=AF=AD=E8=A8=80=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E6=94=AF=E6=8C=81=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E5=85=A8=E9=87=8F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - names.ts 新增 getSpeciesI18nName() 按 lang 获取名称 - 自动尝试加载 species-names.ts 生成数据(如已生成) - 保留 10 个手工校对条目作为回退 - 配合 fetch-species-names.ts 脚本可获取 1024 个物种中/日名称 - 解决 #18 多语言名称覆盖极少 Co-Authored-By: Claude Opus 4.7 --- packages/pokemon/src/dex/names.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/pokemon/src/dex/names.ts b/packages/pokemon/src/dex/names.ts index 8e571702c..9f388c9ce 100644 --- a/packages/pokemon/src/dex/names.ts +++ b/packages/pokemon/src/dex/names.ts @@ -15,7 +15,7 @@ export const SPECIES_NAMES: Partial> = { } /** Curated multilingual names (falls back to English from Dex) */ -export const SPECIES_I18N: Partial>> = { +const CURATED_I18N: Partial>> = { bulbasaur: { en: 'Bulbasaur', ja: 'フシギダネ', zh: '妙蛙种子' }, ivysaur: { en: 'Ivysaur', ja: 'フシギソウ', zh: '妙蛙草' }, venusaur: { en: 'Venusaur', ja: 'フシギバナ', zh: '妙蛙花' }, @@ -28,6 +28,33 @@ export const SPECIES_I18N: Partial>> = { pikachu: { en: 'Pikachu', ja: 'ピカチュウ', zh: '皮卡丘' }, } +// Try loading auto-generated multilingual data (from fetch-species-names.ts) +let generatedI18n: Record> = {} +try { + // eslint-disable-next-line @typescript-eslint/no-require-imports + const mod = require('./species-names.ts') as { SPECIES_I18N_DATA?: Record } + if (mod.SPECIES_I18N_DATA) { + generatedI18n = mod.SPECIES_I18N_DATA + } +} catch { + // species-names.ts not generated yet — use curated fallback +} + +/** Get multilingual name for a species. Falls back to Dex English name. */ +export function getSpeciesI18nName(speciesId: SpeciesId, lang: string): string { + const generated = generatedI18n[speciesId] + if (generated) return generated[lang] ?? generated.en ?? speciesId + const curated = CURATED_I18N[speciesId] + if (curated) return curated[lang] ?? curated.en ?? speciesId + return speciesId +} + +/** All available multilingual names (curated + auto-generated) */ +export const SPECIES_I18N: Partial>> = { + ...CURATED_I18N, + ...generatedI18n, +} + /** Curated personality descriptions (falls back to empty string) */ export const SPECIES_PERSONALITY: Partial> = { bulbasaur: 'Calm and collected, a reliable partner',