Skip to content

feat: knowledge restrieval translation - #8001

Closed
shaohuzhang1 wants to merge 1 commit into
v3from
pr@v3@feat_translation_knowledge
Closed

shaohuzhang1 wants to merge 1 commit into
v3from
pr@v3@feat_translation_knowledge

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

feat: knowledge restrieval translation

<el-table-column prop="update_time" :label="t('application.chatLog.labels.lastChatTime')" width="180" sortable>
<template #default="{ row }">{{ datetimeFormat(row.update_time) }}</template>
</el-table-column>
<template #footer-batch-actions>

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.

Reviewed the diff. Overall the i18n migration is sensible (constants moved to message keys, options turned into computed so they react to locale changes). Issues/suggestions below.

Potential bugs / correctness

  1. searchFields changed from a plain array to a ComputedRef — the type of the variable changed from OptionItem<string>[] to ComputedRef<OptionItem<string>[]>. In templates this auto-unwraps, but any usage in script (e.g. passed to a render function, h(Component, { fields: searchFields }), or spread/mutated by a child) will now break or pass a ref object. Verify all usages, and be aware a consumer that mutates the passed array will fail (computed is read‑only / recreated each time).
  2. formatSource relies on t() being tracked by the render effect. It works as long as it's only called from the template. If it's ever called inside watch, a non‑reactive callback, or a cached value, the source column will not update on locale switch. Consider making it a computed map (Record<string, string>) instead.
  3. sourceKey ? t(sourceKey) : source — TS types Record<ChatLogSource, string> indexing as always string, so the falsy check is "unnecessary" to the compiler (it will not narrow) but correct at runtime. Better: use a Partial<Record<...>> or a helper with Object.prototype.hasOwnProperty so the guard is type‑honest. Also t(dynamicKey) will emit "missing key" warnings in dev for unknown sources — guard still needed.
  4. application.value?.name ?? t('application.chatLog.title') — ?? does not fall back on empty string; the previous code had the same flaw, but since this value is used as an export filename, consider || and think about whether a translated default is appropriate for a file name (non‑ASCII / locale‑dependent naming on the server side).
  5. Object.entries(CHAT_LOG_SOURCE_MESSAGE_KEYS) widens keys to string, which is why source as ChatLogSource casts exist elsewhere. Typing the helper (Object.keys(...) as ChatLogSource[] or a typed entries util) removes the casts and catches future key mismatches.

i18n specifics

  1. Key naming inconsistency: application.chatLog.labels.* vs application.chatLog.source.label / application.chatLog.feedback.label. source.label and feedback.label look like they should be labels.source / labels.feedback (or source.title) — mixing label/labels will cause confusion later. Also verify common.actions.export actually exists in the global messages.
  2. Missing coverage: the diff translates the table headers, export button, and filter labels, but check the remaining user‑facing strings in the file/children (page title/header, empty state, drawer title, search placeholders, MkTableFilter placeholder, batch action labels, CHAT_LOG_SOURCE values not in the map). The '-' placeholder is fine.
  3. useI18n({ useScope: 'global' }) — fine with Composition API mode; if the app is configured with legacy: true only, useI18n will throw. Also, if the project wraps i18n (e.g. @/hooks/useI18n), prefer that for consistency.
  4. Consider typed message keys (vue-i18n schema augmentation or defineI18n typing) so missing keys fail at build time — currently a typo in a key silently renders the key in production.

Layout / styling

  1. Width changes are inconsistent and may overflow: width → min-width for chat_record_count (100→130), feedback (140→150), mark_sum (100→120), while IP 地址 (140) and update_time (180) stay fixed. Mixed width/min-width plus larger minimums on a resizable table can exceed the container and force horizontal scrolling. Decide on a consistent policy (auto‑width short/numeric columns, fixed width only where truncation is acceptable) and test with the longest translation.
  2. Translated labels can be much longer than the Chinese originals — fixed widths (width="140", width="180") will truncate headers in other locales. Either keep min-width everywhere or verify per locale.
  3. Minor: numeric columns (chat_record_count, mark_sum) may deserve align="center".

Optimizations / nits

  1. sourceOptions recomputes only on locale change — good. No need to memoize further.
  2. formatSource could reuse a computed Map<ChatLogSource, string> of translated labels instead of doing a t() lookup per cell, especially if resizable makes the table re‑render often.
  3. handleExport calling t() inside the promise chain is fine (it's synchronous), but if you need the export name independent of UI locale, pass an explicit constant instead.
  4. Confirm CHAT_LOG_SOURCE_MESSAGE_KEYS rename is applied everywhere (grep for CHAT_LOG_SOURCE_LABELS), including tests/mocks.

</el-button>
</template>
</MkDrawer>
</template>

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 a review of the diff with potential issues and suggestions:

Potential Issues

  1. option.labelKey / option.tipKey may be undefined

    {{ t(option.labelKey) }}
    {{ t(option.tipKey) }}

    Unlike field.labelKey (which has a fallback to field.label ?? field.key), the option fields have no fallback. If either key is missing, t(undefined) will likely render an error/key path. Add fallbacks or make the type enforce the keys.

  2. Inconsistent i18n strategy for callbackTip vs consoleNameKey

    • platform.consoleNameKey is checked before use (v-if="... && platform.consoleNameKey"), good.
    • But t(\application.access.${platform.key}.callbackTip`)` is used unconditionally — if that key doesn't exist, you'll get the raw key rendered or a warning rather than hiding it. Either keep both in sync or guard it similarly.
  3. **t(\application.access.${platform.key}.label`)dynamic key** Dynamic, template-composed keys break static extraction tools (e.g.,@intlify/vite-plugin-vue-i18n`, i18n-ally). Consider ensuring these keys are whitelisted/enumerated, or add an explicit map so extraction works.

  4. activeFields loses reactivity on locale changes (subtle)
    computed in Vue does track locale via t() if t reads reactive state — usually fine with vue-i18n. But double-check: useI18n({ useScope: 'global' })'s t does react to locale changes. Verify no memoization issue in your setup (e.g., SSR/hydration ordering), since labels are now baked into the computed.

  5. Label duplication between rules and placeholders
    rules uses field.label which is now the translated label from activeFields. This is correct, but re-evaluates rules whenever locale changes — with :validate-on-rule-change="false" this is safe (good addition). Just be aware validation messages won't update live while form is displayed after a locale switch until re-validation.

  6. msgSuccess(t('common.messages.saveSuccess')) — fine, but confirm MsgSuccess doesn't already i18n-wrap internally; otherwise double translation risk isn't present here (it takes a string), just noting to verify.

  7. copyText(callbackUrl, t('common.messages.copied')) — verify the signature of copyText accepts a custom success message as second parameter; if it previously took only one arg, this could silently break the copy feedback. Check the helper's definition.

  8. Non-reactive label in nested returns
    fields.map((field) => ({ ...field, label: ... })) — if props.platform.fields items are frozen/shared references, spreading is fine, but ensure downstream consumers don't rely on reference identity with props.platform.fields.

  9. Removed field.label usage — the label field now always overrides any original label with a translated one. Confirm ApplicationAccessDefinition fields no longer rely on the raw label for anything else (e.g., comparing by label).

  10. Type narrowing of ApplicationAccessPermissionMethod
    Collapsing the union to 'accessEdit' is fine now, but if more methods are added later, the single-line type is easy to miss in diffs. Minor style note.

Optimization Suggestions

  • Centralize the field-label resolution into a small helper (resolveFieldLabel(field)) used by both activeFields and anywhere else, to avoid drift.
  • Extract option label/tip resolution symmetrically:
    { ...option, label: option.labelKey ? t(option.labelKey) : option.label }
    or enforce labelKey/tipKey as required in the type.
  • Guard callbackTip similarly to consoleNameKey:
    <template v-if="platform.callbackTip || platform.callbackTipKey">...</template>
  • Consider t() with explicit msg fallback: t(key, key) renders the key itself instead of throwing/warning when missing — useful for dynamic composed keys.
  • Add a unit test asserting all platform.*.labelKey, .callbackTip, and .modeField.options[*].labelKey/tipKey resolve to existing keys across every platform, to catch the missing-fallback cases (build(deps): bump the pip group across 1 directory with 2 updates #1, build(deps): bump the pip group across 1 directory with 1 update #2).

Minor Nits

  • Template expression inside :title is getting long; consider a computed drawerTitle.
  • The multi-line t(...) inside template attributes is valid but reduces readability; extracting to a computed would be cleaner.
  • isWechat and other boolean computeds still likely use hardcoded logic — no issue, just noting no i18n concern there.

Overall the change is sound. The main risks are (1) undefined labelKey/tipKey on options and (2) unconditional callbackTip key — those should be addressed to avoid rendering raw/missing i18n keys.

@wangdan-fit2cloud
wangdan-fit2cloud deleted the pr@v3@feat_translation_knowledge branch November 19, 2026 03:34
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