From 1589851592ce8613af8b2f5668700f9e4449e507 Mon Sep 17 00:00:00 2001 From: panw Date: Wed, 29 Apr 2026 10:39:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(i18n):=20=E6=89=A9=E5=B1=95=E7=BF=BB?= =?UTF-8?q?=E8=AF=91=E5=87=BD=E6=95=B0=E6=94=AF=E6=8C=81=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=B9=B6=E6=9B=B4=E6=96=B0=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 I18nString 类以支持参数替换,将阈值等动态值插入翻译文本 - 更新多个配置文件中的翻译调用,传入相应的参数值 - 修正中文语言文件中的导航栏标签文本 --- assets/resources/language/json/zh.json | 6 +- assets/script/game/common/config/CardSet.ts | 19 +++- .../script/game/common/config/HighlightSet.ts | 99 ++++++++++--------- assets/script/game/common/config/SkillSet.ts | 21 ++-- assets/script/game/common/config/heroSet.ts | 19 +++- 5 files changed, 100 insertions(+), 64 deletions(-) diff --git a/assets/resources/language/json/zh.json b/assets/resources/language/json/zh.json index 4505ef48..81cc9e25 100644 --- a/assets/resources/language/json/zh.json +++ b/assets/resources/language/json/zh.json @@ -22,8 +22,8 @@ "role_physical": "体质", "role_agile": "敏捷", "bar_heros": "英雄", - "bar_ranks": "英雄", - "bar_talents": "英雄", + "bar_ranks": "排行榜", + "bar_talents": "天赋", "htype_melee": "近战", @@ -126,7 +126,7 @@ "skill_name_6303": "护盾", "skill_name_6501": "复活", - "skill_info_6001": "对单个造成100%攻击的伤害", + "skill_info_6001": "对单个造成{0}%攻击的伤害", "skill_info_6002": "对单个目标造成100%攻击的伤害,冰冻率20%", "skill_info_6003": "对单个目标造成100%攻击的伤害", "skill_info_6004": "对单个目标造成100%攻击的伤害", diff --git a/assets/script/game/common/config/CardSet.ts b/assets/script/game/common/config/CardSet.ts index e68377bf..23347530 100644 --- a/assets/script/game/common/config/CardSet.ts +++ b/assets/script/game/common/config/CardSet.ts @@ -4,13 +4,22 @@ import { FightSet } from "./GameSet" import { oops } from "db://oops-framework/core/Oops" class I18nString { - constructor(private key: string) {} - toString() { return oops.language.getLangByID(this.key) || this.key; } - valueOf() { return oops.language.getLangByID(this.key) || this.key; } - toJSON() { return oops.language.getLangByID(this.key) || this.key; } + constructor(private key: string, private params?: any[]) {} + private getTranslated(): string { + let str = oops.language.getLangByID(this.key) || this.key; + if (this.params && this.params.length > 0) { + for (let i = 0; i < this.params.length; i++) { + str = str.replace(`{${i}}`, String(this.params[i])); + } + } + return str; + } + toString() { return this.getTranslated(); } + valueOf() { return this.getTranslated(); } + toJSON() { return this.getTranslated(); } get length() { return this.toString().length; } } -const t = (key: string) => new I18nString(key) as unknown as string; +const t = (key: string, ...params: any[]) => new I18nString(key, params) as unknown as string; /** 卡牌大类定义 */ export enum CardType { diff --git a/assets/script/game/common/config/HighlightSet.ts b/assets/script/game/common/config/HighlightSet.ts index 26341192..172a654e 100644 --- a/assets/script/game/common/config/HighlightSet.ts +++ b/assets/script/game/common/config/HighlightSet.ts @@ -9,13 +9,22 @@ import { oops } from "db://oops-framework/core/Oops" class I18nString { - constructor(private key: string) {} - toString() { return oops.language.getLangByID(this.key) || this.key; } - valueOf() { return oops.language.getLangByID(this.key) || this.key; } - toJSON() { return oops.language.getLangByID(this.key) || this.key; } + constructor(private key: string, private params?: any[]) {} + private getTranslated(): string { + let str = oops.language.getLangByID(this.key) || this.key; + if (this.params && this.params.length > 0) { + for (let i = 0; i < this.params.length; i++) { + str = str.replace(`{${i}}`, String(this.params[i])); + } + } + return str; + } + toString() { return this.getTranslated(); } + valueOf() { return this.getTranslated(); } + toJSON() { return this.getTranslated(); } get length() { return this.toString().length; } } -const t = (key: string) => new I18nString(key) as unknown as string; +const t = (key: string, ...params: any[]) => new I18nString(key, params) as unknown as string; export enum HighlightType { CritMaster = "CritMaster", // 暴击大师 @@ -48,66 +57,66 @@ export const HighlightSet: Record = { type: HighlightType.CritMaster, icon: "🔥", levels: [ - { level: 1, threshold: 20, scoreBonus: 50, title: t("hl_title_CritMaster_1"), desc: t("hl_desc_CritMaster") }, - { level: 2, threshold: 40, scoreBonus: 100, title: t("hl_title_CritMaster_2"), desc: t("hl_desc_CritMaster") }, - { level: 3, threshold: 60, scoreBonus: 150, title: t("hl_title_CritMaster_3"), desc: t("hl_desc_CritMaster") }, - { level: 4, threshold: 80, scoreBonus: 200, title: t("hl_title_CritMaster_4"), desc: t("hl_desc_CritMaster") }, - { level: 5, threshold: 100, scoreBonus: 300, title: t("hl_title_CritMaster_5"), desc: t("hl_desc_CritMaster") }, + { level: 1, threshold: 20, scoreBonus: 50, title: t("hl_title_CritMaster_1"), desc: t("hl_desc_CritMaster", 20) }, + { level: 2, threshold: 40, scoreBonus: 100, title: t("hl_title_CritMaster_2"), desc: t("hl_desc_CritMaster", 40) }, + { level: 3, threshold: 60, scoreBonus: 150, title: t("hl_title_CritMaster_3"), desc: t("hl_desc_CritMaster", 60) }, + { level: 4, threshold: 80, scoreBonus: 200, title: t("hl_title_CritMaster_4"), desc: t("hl_desc_CritMaster", 80) }, + { level: 5, threshold: 100, scoreBonus: 300, title: t("hl_title_CritMaster_5"), desc: t("hl_desc_CritMaster", 100) }, ] }, [HighlightType.DeathExpert]: { type: HighlightType.DeathExpert, icon: "💀", levels: [ - { level: 1, threshold: 15, scoreBonus: 50, title: t("hl_title_DeathExpert_1"), desc: t("hl_desc_DeathExpert") }, - { level: 2, threshold: 25, scoreBonus: 100, title: t("hl_title_DeathExpert_2"), desc: t("hl_desc_DeathExpert") }, - { level: 3, threshold: 40, scoreBonus: 150, title: t("hl_title_DeathExpert_3"), desc: t("hl_desc_DeathExpert") }, - { level: 4, threshold: 60, scoreBonus: 200, title: t("hl_title_DeathExpert_4"), desc: t("hl_desc_DeathExpert") }, - { level: 5, threshold: 80, scoreBonus: 300, title: t("hl_title_DeathExpert_5"), desc: t("hl_desc_DeathExpert") }, + { level: 1, threshold: 15, scoreBonus: 50, title: t("hl_title_DeathExpert_1"), desc: t("hl_desc_DeathExpert", 15) }, + { level: 2, threshold: 25, scoreBonus: 100, title: t("hl_title_DeathExpert_2"), desc: t("hl_desc_DeathExpert", 25) }, + { level: 3, threshold: 40, scoreBonus: 150, title: t("hl_title_DeathExpert_3"), desc: t("hl_desc_DeathExpert", 40) }, + { level: 4, threshold: 60, scoreBonus: 200, title: t("hl_title_DeathExpert_4"), desc: t("hl_desc_DeathExpert", 60) }, + { level: 5, threshold: 80, scoreBonus: 300, title: t("hl_title_DeathExpert_5"), desc: t("hl_desc_DeathExpert", 80) }, ] }, [HighlightType.IronWall]: { type: HighlightType.IronWall, icon: "🛡️", levels: [ - { level: 1, threshold: 15, scoreBonus: 50, title: t("hl_title_IronWall_1"), desc: t("hl_desc_IronWall") }, - { level: 2, threshold: 30, scoreBonus: 100, title: t("hl_title_IronWall_2"), desc: t("hl_desc_IronWall") }, - { level: 3, threshold: 50, scoreBonus: 150, title: t("hl_title_IronWall_3"), desc: t("hl_desc_IronWall") }, - { level: 4, threshold: 70, scoreBonus: 200, title: t("hl_title_IronWall_4"), desc: t("hl_desc_IronWall") }, - { level: 5, threshold: 100, scoreBonus: 300, title: t("hl_title_IronWall_5"), desc: t("hl_desc_IronWall") }, + { level: 1, threshold: 15, scoreBonus: 50, title: t("hl_title_IronWall_1"), desc: t("hl_desc_IronWall", 15) }, + { level: 2, threshold: 30, scoreBonus: 100, title: t("hl_title_IronWall_2"), desc: t("hl_desc_IronWall", 30) }, + { level: 3, threshold: 50, scoreBonus: 150, title: t("hl_title_IronWall_3"), desc: t("hl_desc_IronWall", 50) }, + { level: 4, threshold: 70, scoreBonus: 200, title: t("hl_title_IronWall_4"), desc: t("hl_desc_IronWall", 70) }, + { level: 5, threshold: 100, scoreBonus: 300, title: t("hl_title_IronWall_5"), desc: t("hl_desc_IronWall", 100) }, ] }, [HighlightType.WindStorm]: { type: HighlightType.WindStorm, icon: "⚡", levels: [ - { level: 1, threshold: 10, scoreBonus: 50, title: t("hl_title_WindStorm_1"), desc: t("hl_desc_WindStorm") }, - { level: 2, threshold: 20, scoreBonus: 100, title: t("hl_title_WindStorm_2"), desc: t("hl_desc_WindStorm") }, - { level: 3, threshold: 35, scoreBonus: 150, title: t("hl_title_WindStorm_3"), desc: t("hl_desc_WindStorm") }, - { level: 4, threshold: 50, scoreBonus: 200, title: t("hl_title_WindStorm_4"), desc: t("hl_desc_WindStorm") }, - { level: 5, threshold: 70, scoreBonus: 300, title: t("hl_title_WindStorm_5"), desc: t("hl_desc_WindStorm") }, + { level: 1, threshold: 10, scoreBonus: 50, title: t("hl_title_WindStorm_1"), desc: t("hl_desc_WindStorm", 10) }, + { level: 2, threshold: 20, scoreBonus: 100, title: t("hl_title_WindStorm_2"), desc: t("hl_desc_WindStorm", 20) }, + { level: 3, threshold: 35, scoreBonus: 150, title: t("hl_title_WindStorm_3"), desc: t("hl_desc_WindStorm", 35) }, + { level: 4, threshold: 50, scoreBonus: 200, title: t("hl_title_WindStorm_4"), desc: t("hl_desc_WindStorm", 50) }, + { level: 5, threshold: 70, scoreBonus: 300, title: t("hl_title_WindStorm_5"), desc: t("hl_desc_WindStorm", 70) }, ] }, [HighlightType.OneHitKill]: { type: HighlightType.OneHitKill, icon: "🎯", levels: [ - { level: 1, threshold: 100, scoreBonus: 50, title: t("hl_title_OneHitKill_1"), desc: t("hl_desc_OneHitKill") }, - { level: 2, threshold: 200, scoreBonus: 100, title: t("hl_title_OneHitKill_2"), desc: t("hl_desc_OneHitKill") }, - { level: 3, threshold: 400, scoreBonus: 150, title: t("hl_title_OneHitKill_3"), desc: t("hl_desc_OneHitKill") }, - { level: 4, threshold: 800, scoreBonus: 200, title: t("hl_title_OneHitKill_4"), desc: t("hl_desc_OneHitKill") }, - { level: 5, threshold: 1500, scoreBonus: 300, title: t("hl_title_OneHitKill_5"), desc: t("hl_desc_OneHitKill") }, + { level: 1, threshold: 100, scoreBonus: 50, title: t("hl_title_OneHitKill_1"), desc: t("hl_desc_OneHitKill", 100) }, + { level: 2, threshold: 200, scoreBonus: 100, title: t("hl_title_OneHitKill_2"), desc: t("hl_desc_OneHitKill", 200) }, + { level: 3, threshold: 400, scoreBonus: 150, title: t("hl_title_OneHitKill_3"), desc: t("hl_desc_OneHitKill", 400) }, + { level: 4, threshold: 800, scoreBonus: 200, title: t("hl_title_OneHitKill_4"), desc: t("hl_desc_OneHitKill", 800) }, + { level: 5, threshold: 1500, scoreBonus: 300, title: t("hl_title_OneHitKill_5"), desc: t("hl_desc_OneHitKill", 1500) }, ] }, [HighlightType.HealingLight]: { type: HighlightType.HealingLight, icon: "💊", levels: [ - { level: 1, threshold: 200, scoreBonus: 50, title: t("hl_title_HealingLight_1"), desc: t("hl_desc_HealingLight") }, - { level: 2, threshold: 500, scoreBonus: 100, title: t("hl_title_HealingLight_2"), desc: t("hl_desc_HealingLight") }, - { level: 3, threshold: 1000, scoreBonus: 150, title: t("hl_title_HealingLight_3"), desc: t("hl_desc_HealingLight") }, - { level: 4, threshold: 2000, scoreBonus: 200, title: t("hl_title_HealingLight_4"), desc: t("hl_desc_HealingLight") }, - { level: 5, threshold: 4000, scoreBonus: 300, title: t("hl_title_HealingLight_5"), desc: t("hl_desc_HealingLight") }, + { level: 1, threshold: 200, scoreBonus: 50, title: t("hl_title_HealingLight_1"), desc: t("hl_desc_HealingLight", 200) }, + { level: 2, threshold: 500, scoreBonus: 100, title: t("hl_title_HealingLight_2"), desc: t("hl_desc_HealingLight", 500) }, + { level: 3, threshold: 1000, scoreBonus: 150, title: t("hl_title_HealingLight_3"), desc: t("hl_desc_HealingLight", 1000) }, + { level: 4, threshold: 2000, scoreBonus: 200, title: t("hl_title_HealingLight_4"), desc: t("hl_desc_HealingLight", 2000) }, + { level: 5, threshold: 4000, scoreBonus: 300, title: t("hl_title_HealingLight_5"), desc: t("hl_desc_HealingLight", 4000) }, ] }, [HighlightType.PerfectClear]: { @@ -121,22 +130,22 @@ export const HighlightSet: Record = { type: HighlightType.LuckyKing, icon: "🎲", levels: [ - { level: 1, threshold: 0.6, scoreBonus: 50, title: t("hl_title_LuckyKing_1"), desc: t("hl_desc_LuckyKing") }, - { level: 2, threshold: 0.7, scoreBonus: 100, title: t("hl_title_LuckyKing_2"), desc: t("hl_desc_LuckyKing") }, - { level: 3, threshold: 0.8, scoreBonus: 150, title: t("hl_title_LuckyKing_3"), desc: t("hl_desc_LuckyKing") }, - { level: 4, threshold: 0.9, scoreBonus: 200, title: t("hl_title_LuckyKing_4"), desc: t("hl_desc_LuckyKing") }, - { level: 5, threshold: 1.0, scoreBonus: 300, title: t("hl_title_LuckyKing_5"), desc: t("hl_desc_LuckyKing") }, + { level: 1, threshold: 0.6, scoreBonus: 50, title: t("hl_title_LuckyKing_1"), desc: t("hl_desc_LuckyKing", 60) }, + { level: 2, threshold: 0.7, scoreBonus: 100, title: t("hl_title_LuckyKing_2"), desc: t("hl_desc_LuckyKing", 70) }, + { level: 3, threshold: 0.8, scoreBonus: 150, title: t("hl_title_LuckyKing_3"), desc: t("hl_desc_LuckyKing", 80) }, + { level: 4, threshold: 0.9, scoreBonus: 200, title: t("hl_title_LuckyKing_4"), desc: t("hl_desc_LuckyKing", 90) }, + { level: 5, threshold: 1.0, scoreBonus: 300, title: t("hl_title_LuckyKing_5"), desc: t("hl_desc_LuckyKing", 100) }, ] }, [HighlightType.ThriftyPlayer]: { type: HighlightType.ThriftyPlayer, icon: "💰", levels: [ - { level: 1, threshold: 0.75, scoreBonus: 50, title: t("hl_title_ThriftyPlayer_1"), desc: t("hl_desc_ThriftyPlayer") }, - { level: 2, threshold: 0.85, scoreBonus: 100, title: t("hl_title_ThriftyPlayer_2"), desc: t("hl_desc_ThriftyPlayer") }, - { level: 3, threshold: 0.95, scoreBonus: 150, title: t("hl_title_ThriftyPlayer_3"), desc: t("hl_desc_ThriftyPlayer") }, - { level: 4, threshold: 0.98, scoreBonus: 200, title: t("hl_title_ThriftyPlayer_4"), desc: t("hl_desc_ThriftyPlayer") }, - { level: 5, threshold: 1.00, scoreBonus: 300, title: t("hl_title_ThriftyPlayer_5"), desc: t("hl_desc_ThriftyPlayer") }, + { level: 1, threshold: 0.75, scoreBonus: 50, title: t("hl_title_ThriftyPlayer_1"), desc: t("hl_desc_ThriftyPlayer", 75) }, + { level: 2, threshold: 0.85, scoreBonus: 100, title: t("hl_title_ThriftyPlayer_2"), desc: t("hl_desc_ThriftyPlayer", 85) }, + { level: 3, threshold: 0.95, scoreBonus: 150, title: t("hl_title_ThriftyPlayer_3"), desc: t("hl_desc_ThriftyPlayer", 95) }, + { level: 4, threshold: 0.98, scoreBonus: 200, title: t("hl_title_ThriftyPlayer_4"), desc: t("hl_desc_ThriftyPlayer", 98) }, + { level: 5, threshold: 1.00, scoreBonus: 300, title: t("hl_title_ThriftyPlayer_5"), desc: t("hl_desc_ThriftyPlayer", 100) }, ] } }; diff --git a/assets/script/game/common/config/SkillSet.ts b/assets/script/game/common/config/SkillSet.ts index f91c33d9..2bdddc05 100644 --- a/assets/script/game/common/config/SkillSet.ts +++ b/assets/script/game/common/config/SkillSet.ts @@ -3,13 +3,22 @@ import { Attrs } from "./HeroAttrs"; import { oops } from "db://oops-framework/core/Oops"; class I18nString { - constructor(private key: string) {} - toString() { return oops.language.getLangByID(this.key) || this.key; } - valueOf() { return oops.language.getLangByID(this.key) || this.key; } - toJSON() { return oops.language.getLangByID(this.key) || this.key; } + constructor(private key: string, private params?: any[]) {} + private getTranslated(): string { + let str = oops.language.getLangByID(this.key) || this.key; + if (this.params && this.params.length > 0) { + for (let i = 0; i < this.params.length; i++) { + str = str.replace(`{${i}}`, String(this.params[i])); + } + } + return str; + } + toString() { return this.getTranslated(); } + valueOf() { return this.getTranslated(); } + toJSON() { return this.getTranslated(); } get length() { return this.toString().length; } } -export const t = (key: string) => new I18nString(key) as unknown as string; +export const t = (key: string, ...params: any[]) => new I18nString(key, params) as unknown as string; export enum HSSet { atk = 0, // 普通攻击 @@ -184,7 +193,7 @@ export const SkillSet: Record = { 6001: { uuid:6001,name:t("skill_name_6001"),sp_name:"atk",icon:"1026",TGroup:TGroup.Enemy,readyAnm:"",endAnm:"",act:"atk", DTType:DTType.single,ap:100,hit_count:1,hitcd:0.2,speed:720,with:0,ready:0.2,EAnm:0,DAnm:"",IType:IType.Melee, - RType:RType.linear,EType:EType.collision,buffs:[],info:t("skill_info_6001"), + RType:RType.linear,EType:EType.collision,buffs:[],info:t("skill_info_6001",['1','100']), }, 6002: { uuid:6002,name:t("skill_name_6002"),sp_name:"ball_fire",icon:"1126",TGroup:TGroup.Enemy,readyAnm:"",endAnm:"",act:"atk", diff --git a/assets/script/game/common/config/heroSet.ts b/assets/script/game/common/config/heroSet.ts index 08e25dd6..de976af6 100644 --- a/assets/script/game/common/config/heroSet.ts +++ b/assets/script/game/common/config/heroSet.ts @@ -3,13 +3,22 @@ import { BoxSet, FacSet } from "./GameSet" import { oops } from "db://oops-framework/core/Oops" class I18nString { - constructor(private key: string) {} - toString() { return oops.language.getLangByID(this.key) || this.key; } - valueOf() { return oops.language.getLangByID(this.key) || this.key; } - toJSON() { return oops.language.getLangByID(this.key) || this.key; } + constructor(private key: string, private params?: any[]) {} + private getTranslated(): string { + let str = oops.language.getLangByID(this.key) || this.key; + if (this.params && this.params.length > 0) { + for (let i = 0; i < this.params.length; i++) { + str = str.replace(`{${i}}`, String(this.params[i])); + } + } + return str; + } + toString() { return this.getTranslated(); } + valueOf() { return this.getTranslated(); } + toJSON() { return this.getTranslated(); } get length() { return this.toString().length; } } -export const t = (key: string) => new I18nString(key) as unknown as string; +export const t = (key: string, ...params: any[]) => new I18nString(key, params) as unknown as string; export enum HType { Melee = 0,