Repository navigation
feat: internationalize tool - #7960
Conversation
| tool: hantTool, | ||
| workspace: hantWorkspace, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
The diff looks structurally correct: tool is imported for all three locales, added to MessageSchema, added to the Vue I18n DefineLocaleMessage augmentation, and included in every messages locale object. Import ordering and object key ordering are consistent.
Potential issues / suggestions:
-
No explicit type check on the
messagesobjectMessageSchemais based on thezh-CNJSON files, but themessagesobject itself is not explicitly typed against it.- If
en-US/tool.jsonorzh-Hant/tool.jsonhas missing keys or different value types, TypeScript may not catch it. - Suggested improvement:
const messages = { 'zh-CN': { /* ... */ }, 'en-US': { /* ... */ }, 'zh-Hant': { /* ... */ }, } satisfies Record<'zh-CN' | 'en-US' | 'zh-Hant', MessageSchema>
- This would at least catch missing top-level namespaces and incompatible shapes.
-
Duplicate namespace list in
MessageSchemaandDefineLocaleMessage- The same
auth,dynamicForm,model,common,resource,tool,workspacelist is written twice. - This is easy to forget when adding future namespaces.
- Suggested simplification:
declare module 'vue-i18n' { interface DefineLocaleMessage extends MessageSchema {} }
- The same
-
Verify the actual JSON structures
- Ensure
zh-CN/tool.json,en-US/tool.json, andzh-Hant/tool.jsonhave the same key structure, placeholders, pluralization rules, and ICU syntax. - TypeScript cannot fully validate runtime translation correctness, especially for extra keys or placeholder mismatches.
- Ensure
-
Minor formatting note
- Reformatting the
zh-CNanden-USmessage objects from one line to multiline is fine and improves readability. - Just make sure the project formatter/linter is applied consistently.
- Reformatting the
Overall: no obvious bug in the shown diff. The main improvement is to add stronger type validation for the messages object and reduce duplicated schema declarations.
| /** 必填提示按实际控件区分输入与选择,与运行时控件匹配一样忽略大小写。 */ | ||
| export function isSelectionFieldType(inputType: string) { | ||
| return selectionFieldTypes.has(inputType.toUpperCase()) | ||
| } |
There was a problem hiding this comment.
Here's my review:
Issues & Suggestions
1. Duplication risk (main issue)
This set is hard-coded separately from DYNAMIC_FORM_TYPES. If a new type is added to DYNAMIC_FORM_TYPES (or an existing value changes), this list silently drifts out of sync — the compiler won't catch it. A field could be mis-classified as input vs. selection without any error.
Suggestion: Derive the set from the source of truth, or at least constrain the literal values to DynamicFormInputType so TS flags typos/rank-breakers:
const selectionFieldTypes: ReadonlySet<string> = new Set<DynamicFormInputType>([
'SingleSelect',
// ...
])Note the literals must match the actual casing in DYNAMIC_FORM_TYPES. Using Set<DynamicFormInputType> will immediately reveal if any string is wrong or not a valid value.
2. Case-normalization approach is fragile
Converting everything with .toUpperCase() means the literal strings here ('SingleSelect' → 'SINGLESELECT') must never collide after normalization, and it hides the real casing mismatch between this list and the actual values. If DYNAMIC_FORM_TYPES values are already consistent, prefer exact matching. If case-insensitivity is genuinely required at runtime, prefer .trim().toLowerCase() (more conventional) and keep the literals in their canonical form rather than upper-casing either side at definition time — only normalize at lookup.
3. Function naming / semantics
isSelectionFieldTypename says "selection," but the list includesDatePicker,UploadInput,Model,Knowledge,SwitchInput— these aren't strictly "selection" controls. The JSDoc says it's used for "required hint grouping (input vs. select)". Consider naming itisChoiceLikeFieldType/isNonTextInputType, or rename to reflect the actual purpose (e.g.,requiresLabelHintVariant). Otherwise future readers may miscategorize.- Minor: comment is bilingual/mixed; keep code comments consistent.
4. Signature typing
Accepting string is loose. If callers pass DynamicFormInputType, tighten to that:
export function isSelectionFieldType(inputType: DynamicFormInputType): booleanIf external/untrusted strings can reach it, keep string but guard against undefined/empty (inputType?.toUpperCase() ?? false).
5. Optimization (minor)
.map(...).toUpperCase()during construction is fine; considerObject.freezeorReadonlySettyping to prevent accidental mutation elsewhere (as above).- The
new Set([...].map(...))creates an intermediate array — negligible but you can build directly with a small helper or inline literals if not derived. - Lookup cost is O(1); no perf concern.
6. Export surface
Both the set and function being module-level is fine, but if the set isn't needed externally, keep it non-exported (it already is). Good.
Summary
Most important: tie the set to DynamicFormInputType to prevent drift, and reconsider the naming since several items aren't selections. Case-handling and typing are secondary refinements.
| { labelKey: 'tool.types.workflow', value: TOOL_TYPE.WORKFLOW }, | ||
| { labelKey: 'tool.types.mcp', value: TOOL_TYPE.MCP }, | ||
| { labelKey: 'tool.types.dataSource', value: TOOL_TYPE.DATA_SOURCE }, | ||
| ] satisfies { labelKey: string; value: ToolType | '' }[] |
There was a problem hiding this comment.
Findings and suggestions:
-
Type safety via
satisfiesis good, but consider extracting the item type for reuse:export type ToolTypeOption = { labelKey: string; value: ToolType | '' }; export const TOOL_TYPE_OPTIONS = [...] satisfies ToolTypeOption[];
This also allows consumers to import the element type without redeclaring it.
-
Potential breaking change for consumers:
label→labelKeyrenames the field. Any caller (templates, tests, snapshots) reading.labelwill break silently at runtime since the array type is now inferred, not annotated asOptionItem<...>. Search the codebase forTOOL_TYPE_OPTIONSusages and update them; consider a codemod or a temporary deprecated alias if the surface is large. -
Placeholder values in translation files: ensure every
labelKey(common.labels.all,tool.types.custom,tool.types.skill,tool.types.workflow,tool.types.mcp,tool.types.dataSource) actually exists in all locale bundles. Missing keys usually fall back to the raw key string — add a unit test that asserts all keys resolve (e.g. iterate options witht()and checkt(key) !== key). -
Naming convention: existing labels appear to be fully lowercased paths (
dataSource,skill). Verify they match the project's i18n key convention; mixed casing (dataSource) is fine, but consistency matters. Also confirm whether the previous capitalized display strings ("Skills", "MCP") imply proper nouns that should not be translated — if so, use plain literal labels for those entries instead of keys. -
''as sentinel value: keep as is for compatibility, but ifToolTypewill ever include a real empty-string enum member, considernull/undefined. Also make sure downstream filtering logic treats''as "all" consistently. -
Doc comment referenced "protocol values and translation keys" — accurate; no issue. Minor: JSDoc-style
/** ... */on animportstatement is only attached to the following declaration by some tooling; harmless but slightly unusual placement. Moving it to just aboveTOOL_TYPE_OPTIONSwould be clearer. -
Optimization: If this file becomes the single source of truth for tool-type filtering, consider adding a helper like:
export const getToolTypeLabel = (value: ToolType | '') => TOOL_TYPE_OPTIONS.find(o => o.value === value)?.labelKey;
to avoid duplicated lookup logic across callers.
No functional bugs are visible in the diff itself; the main risks are the field rename (breaking consumers) and missing i18n keys.
feat: internationalize tool