Skip to content

feat: internationalize tool - #7960

Merged
wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@feat_tool_i18n
Nov 17, 2026
Merged

wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@feat_tool_i18n

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

feat: internationalize tool

@wangdan-fit2cloud
wangdan-fit2cloud merged commit b0e01ca into v3 Nov 17, 2026
3 of 4 checks passed
@wangdan-fit2cloud
wangdan-fit2cloud deleted the pr@v3@feat_tool_i18n branch November 17, 2026 01:59
Comment thread ui/src/locales/index.ts
tool: hantTool,
workspace: hantWorkspace,
},
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. No explicit type check on the messages object

    • MessageSchema is based on the zh-CN JSON files, but the messages object itself is not explicitly typed against it.
    • If en-US/tool.json or zh-Hant/tool.json has 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.
  2. Duplicate namespace list in MessageSchema and DefineLocaleMessage

    • The same auth, dynamicForm, model, common, resource, tool, workspace list is written twice.
    • This is easy to forget when adding future namespaces.
    • Suggested simplification:
      declare module 'vue-i18n' {
        interface DefineLocaleMessage extends MessageSchema {}
      }
  3. Verify the actual JSON structures

    • Ensure zh-CN/tool.json, en-US/tool.json, and zh-Hant/tool.json have the same key structure, placeholders, pluralization rules, and ICU syntax.
    • TypeScript cannot fully validate runtime translation correctness, especially for extra keys or placeholder mismatches.
  4. Minor formatting note

    • Reformatting the zh-CN and en-US message objects from one line to multiline is fine and improves readability.
    • Just make sure the project formatter/linter is applied consistently.

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())
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • isSelectionFieldType name says "selection," but the list includes DatePicker, 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 it isChoiceLikeFieldType / 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): boolean

If 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; consider Object.freeze or ReadonlySet typing 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.

Comment thread ui/src/constants/tool.ts
{ 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 | '' }[]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings and suggestions:

  1. Type safety via satisfies is 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.

  2. Potential breaking change for consumers: label → labelKey renames the field. Any caller (templates, tests, snapshots) reading .label will break silently at runtime since the array type is now inferred, not annotated as OptionItem<...>. Search the codebase for TOOL_TYPE_OPTIONS usages and update them; consider a codemod or a temporary deprecated alias if the surface is large.

  3. 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 with t() and check t(key) !== key).

  4. 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.

  5. '' as sentinel value: keep as is for compatibility, but if ToolType will ever include a real empty-string enum member, consider null/undefined. Also make sure downstream filtering logic treats '' as "all" consistently.

  6. Doc comment referenced "protocol values and translation keys" — accurate; no issue. Minor: JSDoc-style /** ... */ on an import statement is only attached to the following declaration by some tooling; harmless but slightly unusual placement. Moving it to just above TOOL_TYPE_OPTIONS would be clearer.

  7. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants