feat(i18n): 扩展翻译函数支持参数替换并更新中文文本

- 修改 I18nString 类以支持参数替换,将阈值等动态值插入翻译文本
- 更新多个配置文件中的翻译调用,传入相应的参数值
- 修正中文语言文件中的导航栏标签文本
This commit is contained in:
panw
2026-04-29 10:39:54 +08:00
parent 0c6ed9159a
commit 1589851592
5 changed files with 100 additions and 64 deletions

View File

@@ -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 {