feat: 多语言名称支持动态加载全量数据

- names.ts 新增 getSpeciesI18nName() 按 lang 获取名称
- 自动尝试加载 species-names.ts 生成数据(如已生成)
- 保留 10 个手工校对条目作为回退
- 配合 fetch-species-names.ts 脚本可获取 1024 个物种中/日名称
- 解决 #18 多语言名称覆盖极少

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-24 08:56:58 +08:00
parent 8c6be4b5d3
commit 192221eafc

View File

@@ -15,7 +15,7 @@ export const SPECIES_NAMES: Partial<Record<string, string>> = {
}
/** Curated multilingual names (falls back to English from Dex) */
export const SPECIES_I18N: Partial<Record<string, Record<string, string>>> = {
const CURATED_I18N: Partial<Record<string, Record<string, string>>> = {
bulbasaur: { en: 'Bulbasaur', ja: 'フシギダネ', zh: '妙蛙种子' },
ivysaur: { en: 'Ivysaur', ja: 'フシギソウ', zh: '妙蛙草' },
venusaur: { en: 'Venusaur', ja: 'フシギバナ', zh: '妙蛙花' },
@@ -28,6 +28,33 @@ export const SPECIES_I18N: Partial<Record<string, Record<string, string>>> = {
pikachu: { en: 'Pikachu', ja: 'ピカチュウ', zh: '皮卡丘' },
}
// Try loading auto-generated multilingual data (from fetch-species-names.ts)
let generatedI18n: Record<string, Record<string, string>> = {}
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const mod = require('./species-names.ts') as { SPECIES_I18N_DATA?: Record<string, { en: string; ja: string; zh: string }> }
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<Record<string, Record<string, string>>> = {
...CURATED_I18N,
...generatedI18n,
}
/** Curated personality descriptions (falls back to empty string) */
export const SPECIES_PERSONALITY: Partial<Record<string, string>> = {
bulbasaur: 'Calm and collected, a reliable partner',