fix: RecipeIn加en_name字段修复共享500错误 + 前端配方名翻译
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 17s
Test / e2e-test (push) Successful in 53s

- RecipeIn 模型添加 en_name 字段,修复共享配方500错误
- recipeNameEn 使用关键词字典翻译,预览卡片英文名不再显示中文

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 13:51:36 +00:00
parent 6f1b9f3f68
commit 28ab51c437
2 changed files with 52 additions and 3 deletions

View File

@@ -99,6 +99,7 @@ class RecipeIn(BaseModel):
note: str = "" note: str = ""
ingredients: list[IngredientIn] ingredients: list[IngredientIn]
tags: list[str] = [] tags: list[str] = []
en_name: Optional[str] = None
class RecipeUpdate(BaseModel): class RecipeUpdate(BaseModel):

View File

@@ -37,10 +37,58 @@ export function oilEn(name) {
return '' return ''
} }
const RECIPE_KEYWORDS = {
'头疗':'Scalp Therapy','头痛':'Headache','偏头痛':'Migraine','头皮':'Scalp','头发':'Hair',
'肩颈':'Neck & Shoulder','颈椎':'Cervical','肩':'Shoulder','腰椎':'Lumbar','腰':'Lower Back',
'关节':'Joint','膝':'Knee','背':'Back','胸':'Chest','腹部':'Abdominal',
'乳腺':'Breast','子宫':'Uterine','私密':'Intimate','卵巢':'Ovarian',
'淋巴':'Lymph','肝':'Liver','肾':'Kidney','脾':'Spleen','胃':'Stomach','肺':'Lung','肠':'Intestinal',
'酸痛':'Pain Relief','疼痛':'Pain Relief','止痛':'Pain Relief',
'感冒':'Cold','发烧':'Fever','咳嗽':'Cough','咽喉':'Throat',
'过敏':'Allergy','鼻炎':'Rhinitis','哮喘':'Asthma',
'湿疹':'Eczema','痘痘':'Acne','粉刺':'Acne',
'消炎':'Anti-Inflammatory','便秘':'Constipation','消化':'Digestion',
'失眠':'Insomnia','助眠':'Sleep Aid','好眠':'Sleep Well','安眠':'Sleep',
'焦虑':'Anxiety','抑郁':'Depression','情绪':'Emotional',
'压力':'Stress','放松':'Relaxation','舒缓':'Soothing',
'水肿':'Edema','痛经':'Menstrual Pain','月经':'Menstrual','更年期':'Menopause','荷尔蒙':'Hormone',
'结节':'Nodule','囊肿':'Cyst','灰指甲':'Nail Fungus','脚气':'Athlete\'s Foot',
'白发':'Gray Hair','脱发':'Hair Loss','生发':'Hair Growth',
'瘦身':'Slimming','紫外线':'UV','抗衰':'Anti-Aging','美白':'Whitening','补水':'Hydrating',
'排毒':'Detox','净化':'Purifying','驱蚊':'Mosquito Repellent',
'护理':'Care','调理':'Therapy','修复':'Repair','养护':'Nourish',
'按摩':'Massage','刮痧':'Gua Sha','泡脚':'Foot Soak','精油浴':'Oil Bath',
'喷雾':'Spray','扩香':'Diffuser',
'疏通':'Unblock','祛湿':'Dampness Relief','驱寒':'Warming','健脾':'Spleen Wellness',
'美容':'Beauty','面膜':'Face Mask','发膜':'Hair Mask',
'配方':'Blend','方':'Blend','包':'Blend',
'增强版':'Enhanced','高配版':'Premium','男士':'Men\'s','儿童':'Children\'s',
'呼吸系统':'Respiratory System','呼吸':'Respiratory','免疫':'Immunity',
'缓解':'Relief','改善':'Improve','预防':'Prevention',
'带脉':'Belt Meridian','经络':'Meridian','静脉曲张':'Varicose Veins',
'口腔溃疡':'Mouth Ulcer','口唇疱疹':'Cold Sore','蚊虫叮咬':'Insect Bite',
'暖宫':'Uterus Warming','调经':'Menstrual Regulation',
}
const _SORTED = Object.keys(RECIPE_KEYWORDS).sort((a, b) => b.length - a.length)
export function recipeNameEn(name) { export function recipeNameEn(name) {
// Try to translate known keywords if (!name) return name
// Simple approach: return original name for now, user can customize const parts = []
return name let i = 0
while (i < name.length) {
let matched = false
for (const key of _SORTED) {
if (name.substring(i, i + key.length) === key) {
const en = RECIPE_KEYWORDS[key]
if (!parts.includes(en)) parts.push(en)
i += key.length
matched = true
break
}
}
if (!matched) i++
}
return parts.length ? parts.join(' ') : name
} }
// Custom translations (can be set by admin) // Custom translations (can be set by admin)