Files
browser/plugins/examples/scum-server-plugin/features/scum-catalog-zh.ts
T

115 lines
7.8 KiB
TypeScript

import type { ScumCatalogEntry } from "./scum-catalog.js";
const directNames: Record<string, string> = {
BP_Bear2: "熊",
BP_Boar: "野猪",
BP_Chicken: "鸡",
BP_Crow: "乌鸦",
BP_Deer2: "鹿",
BP_Donkey2: "驴",
BP_Goat2: "山羊",
BP_Horse2: "马",
BP_Rabbit2: "兔子",
BP_Seagull: "海鸥",
BP_Wolf3: "狼",
WildDuck: "鹿(目录别名)",
BP_Drifter_Lvl_1: "武装 NPC 1 级",
BP_Drifter_Lvl_2: "武装 NPC 2 级",
BP_Drifter_Lvl_3: "武装 NPC 3 级",
BP_Drifter_Lvl_4: "武装 NPC 4 级",
BP_Drifter_Lvl_5: "武装 NPC 5 级",
BP_Guard_Lvl_1: "武装守卫 1 级",
BP_Guard_Lvl_2: "武装守卫 2 级",
BP_Guard_Lvl_3: "武装守卫 3 级",
BP_Guard_Lvl_4: "武装守卫 4 级",
BP_Guard_Lvl_5: "武装守卫 5 级",
BP_Zombie_Hospital_Normal: "医院普通丧尸",
BPC_Laika: "莱卡",
BPC_WolfsWagen: "沃尔夫斯瓦根",
BPC_SidecarBike: "边车摩托",
BPC_Motorcycle: "摩托车",
Aloe_Vera: "芦荟",
Aspirin: "阿司匹林",
Animal_Skin: "动物皮",
Air_Pump: "打气筒",
Backpack_02_01: "红色背包",
"1H_Cleaver": "菜刀",
Water_05l: "水",
BP_Cash_01: "现金",
Cash: "现金",
Adrenaline_Shot: "肾上腺素注射剂",
Antibiotic_Pill_Single: "抗生素药片",
AntiburnGel: "烧伤凝胶",
Bandage: "绷带",
Bread: "面包",
Burger: "汉堡",
Canteen: "水壶",
Fish_trap: "捕鱼陷阱",
FishingRod: "鱼竿",
FishingHook: "鱼钩",
Bait_trap_for_small_animals: "小型动物诱饵陷阱",
Watermelon: "西瓜"
};
const wordNames: Record<string, string> = {
absinthe: "苦艾酒", animal: "动物", animals: "动物", apple: "苹果", armor: "护甲", arrow: "箭", arrows: "箭矢", aspirin: "阿司匹林", advanced: "高级", automatic: "自动",
backpack: "背包", bait: "诱饵", ball: "球", banana: "香蕉", bandage: "绷带", baseball: "棒球", battery: "电池", bear: "熊", beer: "啤酒", beet: "甜菜", berries: "浆果", blackberry: "黑莓", blueberries: "蓝莓", bolt: "弩箭", bottle: "瓶", bow: "弓", bread: "面包", brick: "砖块", broccoli: "西兰花", buck: "雄鹿", bullet: "子弹", bulletproof: "防弹", burger: "汉堡", burn: "烧伤", cake: "蛋糕", canned: "罐装", carbon: "碳纤维", carrot: "胡萝卜", cartridge: "弹药", cash: "现金", cheese: "奶酪", chicken: "鸡", civilian: "平民", cleaver: "菜刀", cola: "可乐", coffee: "咖啡", compound: "复合", construction: "施工", cooked: "熟制", cooking: "烹饪", crow: "乌鸦", crossbow: "弩", crucian: "鲫鱼", cup: "杯", dark: "深色", deer: "鹿", detonator: "雷管", dildo: "假阳具", donkey: "驴", double: "双头", drink: "饮料", drinks: "饮料", eagle: "鹰", edible: "可食用", energy: "能量", explosive: "爆炸", female: "女性", fish: "鱼", fishing: "钓鱼", floater: "浮漂", freshwater: "淡水", fruit: "水果", gas: "燃气", gasoline: "汽油", goat: "山羊", green: "绿色", grenade: "手雷", grey: "灰色", guts: "内脏", hammer: "锤子", hands: "手部", hat: "帽子", head: "头部", helmet: "头盔", hospital: "医院", hook: "鱼钩", horse: "马", human: "人类", improvised: "简易", injection: "注射剂", iron: "铁制", juice: "果汁", katana: "武士刀", knife: "刀", large: "大型", launcher: "发射器", leather: "皮革", level: "等级", lime: "青柠", lock: "锁", lockpick: "撬锁工具", magazine: "弹匣", male: "男性", medical: "医疗", medium: "中型", metal: "金属", milk: "牛奶", mushroom: "蘑菇", muzzle: "枪口", necklace: "项链", nylon: "尼龙", orange: "橙色", pack: "包", packaged: "包装", painkiller: "止痛药", pepper: "胡椒", pill: "药片", pills: "药片", pizza: "披萨", police: "警用", potato: "土豆", red: "红色", repair: "维修", rifle: "步枪", rope: "绳子", rabbit: "兔子", rice: "米饭", revolver: "左轮手枪", salad: "沙拉", sardine: "沙丁鱼", shotgun: "霰弹枪", shovel: "铲子", small: "小型", soda: "汽水", soup: "汤", stone: "石制", suppressor: "消音器", sword: "剑", syringe: "注射器", tea: "茶", tuna: "金枪鱼", vegetables: "蔬菜", vehicle: "载具", vest: "背心", vitamins: "维生素", vodka: "伏特加", water: "水", watermelon: "西瓜", whiskey: "威士忌", white: "白色", wolf: "狼", wooden: "木制", yellow: "黄色", zombie: "丧尸"
};
const additionalWordNames: Record<string, string> = {
activated: "活性炭", alcohol: "酒精", alcoholic: "酒精类", anti: "抗", antibiotic: "抗生素", antimalaria: "抗疟疾", antiparasitic: "抗寄生虫", antipsychotic: "抗精神病", ammunition: "弹药", attachment: "配件", back: "后部", big: "大", body: "身体", boots: "靴子", box: "盒", bucket: "桶", camp: "营地", charcoal: "木炭", clothes: "服装", component: "组件", crafted: "制作的", crafting: "制作", dirty: "脏污", door: "车门", electrodes: "电极", farming: "农业", feet: "脚部", front: "前部", gear: "装备", gloves: "手套", hiking: "徒步", hood: "引擎盖", inventory: "背包栏", item: "物品", legs: "腿部", light: "轻型", military: "军用", normal: "普通", other: "其他", parts: "零件", rear: "后部", rubber: "橡胶", security: "安全", seat: "座椅", side: "侧面", single: "单发", skin: "皮肤", spare: "备用", standing: "立式", steel: "钢制", tactical: "战术", top: "顶部", trap: "陷阱", underwear: "内衣", weapon: "武器", wheel: "车轮"
};
const phraseNames: Array<readonly [RegExp, string]> = [
[/^Armed Guard NPC Level (\d+)$/i, "武装守卫 $1 级"],
[/^Armed NPC Level (\d+)$/i, "武装 NPC $1 级"],
[/^Zombie (.+) Female$/i, "女性丧尸 $1"],
[/^Zombie (.+) Male$/i, "男性丧尸 $1"],
[/^Zombie (.+)$/i, "丧尸 $1"],
[/^(.+) Fish Bait$/i, "$1 鱼饵"],
[/^(.+) Cookbook$/i, "$1 烹饪书"],
[/^(.+) Magazine$/i, "$1 弹匣"],
[/^(.+) Crossbow Bolt$/i, "$1 弩箭"],
[/^(.+) Arrow$/i, "$1 箭"],
[/^(.+) Seed Bag$/i, "$1 种子袋"],
[/^(.+) Seeds$/i, "$1 种子"],
[/^(.+) Juice$/i, "$1 果汁"],
[/^(.+) Beer$/i, "$1 啤酒"],
[/^(.+) Vodka$/i, "$1 伏特加"],
[/^(.+) Water$/i, "$1 水"],
[/^(.+) Level (\d+)$/i, "$1 $2 级"]
];
const catalogKindNames: Record<string, string> = { item: "物品", vehicle: "载具", animal: "动物", zombie: "丧尸", "armed-npc": "NPC", razor: "其他" };
export function scumCatalogNameZh(entry: ScumCatalogEntry): string {
const direct = directNames[entry.code];
if (direct) return direct;
const source = usableName(entry);
for (const [pattern, replacement] of phraseNames) if (pattern.test(source)) return translateWords(source.replace(pattern, replacement));
const translated = translateWords(source);
return translated === source ? `${catalogKindNames[entry.kind] ?? "物品"} · ${source}` : translated;
}
export function scumCatalogDisplayName(entry: ScumCatalogEntry): string { return scumCatalogNameZh(entry); }
export function scumCatalogSearchText(entry: ScumCatalogEntry): string {
const codeWords = entry.code.replace(/[_-]+/g, " ");
const aliases = [
/(?:big|large).*backpack|backpack.*(?:big|large)/i.test(codeWords) ? "大背包" : "",
/military.*backpack|backpack.*military/i.test(codeWords) ? "军用背包" : "",
/military.*helmet|helmet.*military/i.test(codeWords) ? "军用头盔" : ""
].filter(Boolean);
const source = [scumCatalogNameZh(entry), entry.name, entry.code, codeWords, entry.command, ...aliases].join(" ").toLowerCase();
return source + " " + source.replace(/[\s._-]+/g, "");
}
function usableName(entry: ScumCatalogEntry): string {
return /^ICO[_ .]/i.test(entry.name) || /\.(?:png|webp)$/i.test(entry.name) ? entry.code.replace(/[_-]+/g, " ") : entry.name;
}
function translateWords(value: string): string {
const spaced = value.replace(/([a-z])([A-Z])/g, "$1 $2");
return spaced.replace(/[A-Za-z][A-Za-z'-]*/g, (word) => additionalWordNames[word.toLowerCase()] ?? wordNames[word.toLowerCase()] ?? word);
}