From a49c99c528d26e57d622219d882f5b6436530aa1 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Fri, 10 Apr 2026 10:45:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(config):=20=E6=B7=BB=E5=8A=A0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=AA=8C=E8=AF=81=E5=8A=9F=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现配置架构解析器,支持对象、数组和标量类型的递归解析 - 添加 YAML 配置文件解析和注释提取功能 - 实现配置验证诊断系统,支持多种数据类型的校验 - 添加表单更新应用功能,支持标量和数组值的批量编辑 - 实现配置示例生成功能,包含架构描述作为 YAML 注释 - 添加国际化支持,提供中英文验证消息本地化 - 实现精确十进制运算,确保数值约束验证的准确性 - 添加批处理数组值解析和枚举值标准化功能 --- .../src/configValidation.js | 8 +++++++ .../src/localization.js | 4 ++++ .../test/localization.test.js | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/tools/gframework-config-tool/src/configValidation.js b/tools/gframework-config-tool/src/configValidation.js index abf64f60..868f513d 100644 --- a/tools/gframework-config-tool/src/configValidation.js +++ b/tools/gframework-config-tool/src/configValidation.js @@ -1091,6 +1091,10 @@ function localizeValidationMessage(key, localizer, params) { } if (key === ValidationMessageKeys.minPropertiesViolation) { + if (localizer && typeof localizer.t === "function" && params.displayPath) { + return localizer.t(key, params); + } + return formatObjectPropertyCountMessage( params.displayPath, params.value, @@ -1099,6 +1103,10 @@ function localizeValidationMessage(key, localizer, params) { } if (key === ValidationMessageKeys.maxPropertiesViolation) { + if (localizer && typeof localizer.t === "function" && params.displayPath) { + return localizer.t(key, params); + } + return formatObjectPropertyCountMessage( params.displayPath, params.value, diff --git a/tools/gframework-config-tool/src/localization.js b/tools/gframework-config-tool/src/localization.js index 839177e9..c6e807f4 100644 --- a/tools/gframework-config-tool/src/localization.js +++ b/tools/gframework-config-tool/src/localization.js @@ -136,10 +136,12 @@ const enMessages = { [ValidationMessageKeys.maximumViolation]: "Property '{displayPath}' must be less than or equal to {value}.", [ValidationMessageKeys.maxItemsViolation]: "Property '{displayPath}' must contain at most {value} items.", [ValidationMessageKeys.maxLengthViolation]: "Property '{displayPath}' must be at most {value} characters long.", + [ValidationMessageKeys.maxPropertiesViolation]: "Property '{displayPath}' must contain at most {value} properties.", [ValidationMessageKeys.minimumViolation]: "Property '{displayPath}' must be greater than or equal to {value}.", [ValidationMessageKeys.multipleOfViolation]: "Property '{displayPath}' must be a multiple of {value}.", [ValidationMessageKeys.minItemsViolation]: "Property '{displayPath}' must contain at least {value} items.", [ValidationMessageKeys.minLengthViolation]: "Property '{displayPath}' must be at least {value} characters long.", + [ValidationMessageKeys.minPropertiesViolation]: "Property '{displayPath}' must contain at least {value} properties.", [ValidationMessageKeys.patternViolation]: "Property '{displayPath}' must match pattern '{value}'.", [ValidationMessageKeys.uniqueItemsViolation]: "Property '{displayPath}' duplicates earlier array item '{duplicatePath}', but uniqueItems is required.", [ValidationMessageKeys.enumMismatch]: "Property '{displayPath}' must be one of: {values}.", @@ -241,10 +243,12 @@ const zhCnMessages = { [ValidationMessageKeys.maximumViolation]: "属性“{displayPath}”必须小于或等于 {value}。", [ValidationMessageKeys.maxItemsViolation]: "属性“{displayPath}”最多只能包含 {value} 个元素。", [ValidationMessageKeys.maxLengthViolation]: "属性“{displayPath}”长度必须不超过 {value} 个字符。", + [ValidationMessageKeys.maxPropertiesViolation]: "对象属性“{displayPath}”最多只能包含 {value} 个子属性。", [ValidationMessageKeys.minimumViolation]: "属性“{displayPath}”必须大于或等于 {value}。", [ValidationMessageKeys.multipleOfViolation]: "属性“{displayPath}”必须是 {value} 的整数倍。", [ValidationMessageKeys.minItemsViolation]: "属性“{displayPath}”至少需要包含 {value} 个元素。", [ValidationMessageKeys.minLengthViolation]: "属性“{displayPath}”长度必须至少为 {value} 个字符。", + [ValidationMessageKeys.minPropertiesViolation]: "对象属性“{displayPath}”至少需要包含 {value} 个子属性。", [ValidationMessageKeys.patternViolation]: "属性“{displayPath}”必须匹配正则模式“{value}”。", [ValidationMessageKeys.uniqueItemsViolation]: "属性“{displayPath}”与更早的数组元素“{duplicatePath}”重复;该数组要求元素唯一。", [ValidationMessageKeys.enumMismatch]: "属性“{displayPath}”必须是以下值之一:{values}。", diff --git a/tools/gframework-config-tool/test/localization.test.js b/tools/gframework-config-tool/test/localization.test.js index 503eae15..2fb40ceb 100644 --- a/tools/gframework-config-tool/test/localization.test.js +++ b/tools/gframework-config-tool/test/localization.test.js @@ -1,6 +1,7 @@ const test = require("node:test"); const assert = require("node:assert/strict"); const {createLocalizer} = require("../src/localization"); +const {ValidationMessageKeys} = require("../src/localizationKeys"); test("createLocalizer should default to English strings", () => { const localizer = createLocalizer("en"); @@ -34,3 +35,25 @@ test("createLocalizer should fall back to English for Traditional Chinese locale localizer.t("message.batchEditUpdated", {count: 2, domain: "monster"}), "Batch updated 2 config file(s) in 'monster'."); }); + +test("createLocalizer should expose object property-count validation keys in English", () => { + const localizer = createLocalizer("en"); + + assert.equal( + localizer.t(ValidationMessageKeys.minPropertiesViolation, {displayPath: "reward", value: 2}), + "Property 'reward' must contain at least 2 properties."); + assert.equal( + localizer.t(ValidationMessageKeys.maxPropertiesViolation, {displayPath: "reward", value: 3}), + "Property 'reward' must contain at most 3 properties."); +}); + +test("createLocalizer should expose object property-count validation keys in Simplified Chinese", () => { + const localizer = createLocalizer("zh-cn"); + + assert.equal( + localizer.t(ValidationMessageKeys.minPropertiesViolation, {displayPath: "reward", value: 2}), + "对象属性“reward”至少需要包含 2 个子属性。"); + assert.equal( + localizer.t(ValidationMessageKeys.maxPropertiesViolation, {displayPath: "reward", value: 3}), + "对象属性“reward”最多只能包含 3 个子属性。"); +});