Repository navigation
feat: knowledge restrieval translation - #8001
shaohuzhang1 wants to merge 1 commit into
Conversation
| <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> |
There was a problem hiding this comment.
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
searchFieldschanged from a plain array to aComputedRef— the type of the variable changed fromOptionItem<string>[]toComputedRef<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).formatSourcerelies ont()being tracked by the render effect. It works as long as it's only called from the template. If it's ever called insidewatch, a non‑reactive callback, or a cached value, the source column will not update on locale switch. Consider making it acomputedmap (Record<string, string>) instead.sourceKey ? t(sourceKey) : source— TS typesRecord<ChatLogSource, string>indexing as alwaysstring, so the falsy check is "unnecessary" to the compiler (it will not narrow) but correct at runtime. Better: use aPartial<Record<...>>or a helper withObject.prototype.hasOwnPropertyso the guard is type‑honest. Alsot(dynamicKey)will emit "missing key" warnings in dev for unknown sources — guard still needed.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).Object.entries(CHAT_LOG_SOURCE_MESSAGE_KEYS)widens keys tostring, which is whysource as ChatLogSourcecasts exist elsewhere. Typing the helper (Object.keys(...) as ChatLogSource[]or a typedentriesutil) removes the casts and catches future key mismatches.
i18n specifics
- Key naming inconsistency:
application.chatLog.labels.*vsapplication.chatLog.source.label/application.chatLog.feedback.label.source.labelandfeedback.labellook like they should belabels.source/labels.feedback(orsource.title) — mixinglabel/labelswill cause confusion later. Also verifycommon.actions.exportactually exists in the global messages. - 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,
MkTableFilterplaceholder, batch action labels,CHAT_LOG_SOURCEvalues not in the map). The'-'placeholder is fine. useI18n({ useScope: 'global' })— fine with Composition API mode; if the app is configured withlegacy: trueonly,useI18nwill throw. Also, if the project wraps i18n (e.g.@/hooks/useI18n), prefer that for consistency.- Consider typed message keys (vue-i18n schema augmentation or
defineI18ntyping) so missing keys fail at build time — currently a typo in a key silently renders the key in production.
Layout / styling
- Width changes are inconsistent and may overflow:
width→min-widthforchat_record_count(100→130), feedback (140→150),mark_sum(100→120), whileIP 地址(140) andupdate_time(180) stay fixed. Mixedwidth/min-widthplus larger minimums on aresizabletable can exceed the container and force horizontal scrolling. Decide on a consistent policy (auto‑width short/numeric columns, fixedwidthonly where truncation is acceptable) and test with the longest translation. - Translated labels can be much longer than the Chinese originals — fixed widths (
width="140",width="180") will truncate headers in other locales. Either keepmin-widtheverywhere or verify per locale. - Minor: numeric columns (
chat_record_count,mark_sum) may deservealign="center".
Optimizations / nits
sourceOptionsrecomputes only on locale change — good. No need to memoize further.formatSourcecould reuse acomputedMap<ChatLogSource, string>of translated labels instead of doing at()lookup per cell, especially ifresizablemakes the table re‑render often.handleExportcallingt()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.- Confirm
CHAT_LOG_SOURCE_MESSAGE_KEYSrename is applied everywhere (grep forCHAT_LOG_SOURCE_LABELS), including tests/mocks.
| </el-button> | ||
| </template> | ||
| </MkDrawer> | ||
| </template> |
There was a problem hiding this comment.
Here's a review of the diff with potential issues and suggestions:
Potential Issues
-
option.labelKey/option.tipKeymay be undefined{{ t(option.labelKey) }} {{ t(option.tipKey) }}
Unlike
field.labelKey(which has a fallback tofield.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. -
Inconsistent i18n strategy for
callbackTipvsconsoleNameKeyplatform.consoleNameKeyis 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.
-
**
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. -
activeFieldsloses reactivity on locale changes (subtle)
computedin Vue does track locale viat()iftreads reactive state — usually fine with vue-i18n. But double-check:useI18n({ useScope: 'global' })'stdoes react tolocalechanges. Verify no memoization issue in your setup (e.g., SSR/hydration ordering), since labels are now baked into the computed. -
Label duplication between rules and placeholders
rulesusesfield.labelwhich is now the translated label fromactiveFields. This is correct, but re-evaluatesruleswhenever 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. -
msgSuccess(t('common.messages.saveSuccess'))— fine, but confirmMsgSuccessdoesn't already i18n-wrap internally; otherwise double translation risk isn't present here (it takes a string), just noting to verify. -
copyText(callbackUrl, t('common.messages.copied'))— verify the signature ofcopyTextaccepts 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. -
Non-reactive
labelin nested returns
fields.map((field) => ({ ...field, label: ... }))— ifprops.platform.fieldsitems are frozen/shared references, spreading is fine, but ensure downstream consumers don't rely on reference identity withprops.platform.fields. -
Removed
field.labelusage — thelabelfield now always overrides any originallabelwith a translated one. ConfirmApplicationAccessDefinitionfields no longer rely on the rawlabelfor anything else (e.g., comparing by label). -
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 bothactiveFieldsand anywhere else, to avoid drift. - Extract option label/tip resolution symmetrically:
or enforce
{ ...option, label: option.labelKey ? t(option.labelKey) : option.label }
labelKey/tipKeyas required in the type. - Guard
callbackTipsimilarly toconsoleNameKey:<template v-if="platform.callbackTip || platform.callbackTipKey">...</template>
- Consider
t()with explicitmsgfallback: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/tipKeyresolve 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
:titleis getting long; consider acomputeddrawerTitle. - The multi-line
t(...)inside template attributes is valid but reduces readability; extracting to a computed would be cleaner. isWechatand 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.
feat: knowledge restrieval translation