Repository navigation
feat: locales for model of edition_1 - #7945
Conversation
| <el-button type="primary" @click="submitEdit">{{ t('common.actions.save') }}</el-button> | ||
| </template> | ||
| </MkDialog> | ||
| </template> |
There was a problem hiding this comment.
Review of the diff
Issues / irregularities
-
Inconsistent key naming for "option value" placeholder
- Label placeholder:
t('dynamicForm.tree.labelPlaceholder')(a "*Placeholder" key) - Value placeholder:
t('dynamicForm.options.valueRequired')— this looks like a required-error message key, not a placeholder. Likely wrong key; placeholders should use a...Placeholderkey (e.g.dynamicForm.options.valuePlaceholder). The same suspicious key is reused in both add and edit dialogs.
- Label placeholder:
-
Wrong namespace mixing (
tree.*vsoptions.*vsfields.*)dynamicForm.options.label/dynamicForm.options.valueare used for field labels, butdynamicForm.fields.defaultValueusesfields.*. This inconsistency will be hard to maintain. Pick one convention.
-
common.actions.editused as a dialog title- Using an action key ("Edit") as a title is a mismatch. Prefer something like
dynamicForm.tree.editTitleorcommon.titles.edit.
- Using an action key ("Edit") as a title is a mismatch. Prefer something like
-
MsgConfirmsignature changed- Original used
('提示', msg, { type }); new version addscancelButtonText/confirmButtonText. Verify thatMsgConfirm's options actually support these keys — otherwise they're silently ignored. Also confirmcommon.titles.noticeexists.
- Original used
-
Formatting / line length
- The
el-form-itemwith:rulesnow has a very long single-line binding. Consider extracting rules into a computed property for readability and reuse. <MkDialog ... :title="addDialog.mode === 'root' ? t(...) : t(...)"— ternary inside template attribute works but is hard to read; consider a computedaddDialogTitle.
- The
-
blur: 'change'in rules objectblurshould be a boolean trigger flag per Element Plus API (trigger: 'change'is typical).blur: 'change'looks incorrect — worth double-checking it wasn't already a latent bug carried over.
-
Mixed i18n scopes
useI18n({ useScope: 'global' })inside script setup plus directt()usage in template — fine, but note that if the component ever needs local messages you'll have to switch scope. Also ensuretreactivity works for<el-form-item :rules>(rules won't re-evaluate on locale change unless wrapped in computed).
-
Rules array recreated on every render
- The inline
:rules="[{ required: true, message: t(...) }]"creates a new array/object each render and capturest()at render time. Wrap incomputed(() => [...])so it updates properly on language change and is stable.
- The inline
-
Hardcoded remaining Chinese
- Search the rest of the file for other untranslated strings (comments are fine, but any UI strings should be checked).
-
.catch(() => {})is silent — acceptable, but consider logging in dev.
Optimization suggestions
- Extract rule arrays to
computedproperties. - Add a
dynamicForm.options.valuePlaceholderkey and use it consistently. - Unify i18n key namespaces (
options.label,options.value,options.valuePlaceholder, etc.). - Move the add-dialog title ternary into a computed.
- Verify
MsgConfirmsupportscancelButtonText/confirmButtonTextand that all referenced keys exist in the locale files (a missing key falls back to the raw key string, which users will see). - Reformat the multi-attribute
el-form-itemto multiple lines for consistency with rest of the file.
| {{ t('common.actions.delete') }} | ||
| </MkDropdownItem> | ||
| </MkTableMoreDropdown> | ||
| </div> |
There was a problem hiding this comment.
Code Review
Potential Issues
-
searchFieldsreactivity bug — This is the most significant issue.searchFieldswas acomputed, but its dependency ont()may not trigger re-evaluation on locale change depending on i18n version/config. More importantly, sincecreatorOptions.valueandremoteMethodare captured inside, changingcreatorOptionswon't recompute unless it's accessed reactively (it is via.value, so OK). But translations won't update on language switch unlesstis reactive in the computed context — generally fine withuseScope: 'global', but worth verifying. -
modelTypeOptionsnow a computed — Correct improvement (fixes stale labels on locale change). Ensure all consumers handle a computed ref; usage in template is fine, butproviderOptions/modelTypeOptionspassed as props will auto-unwrap only in templates. ConfirmMkTableFilter:optionsreceives unwrapped array (template ok). -
Non-null assertion
MODEL_TYPE_LABELS[row.model_type]!— The ternary guard makes this safe, but a cleaner pattern:{{ MODEL_TYPE_LABELS[row.model_type] ?? row.model_type }}
If you want translation:
const label = (v) => MODEL_TYPE_LABELS[v] ? t(MODEL_TYPE_LABELS[v]) : v
-
MsgConfirmsignature change — Verify the 3rd argument ({ cancelButtonText, confirmButtonText }) is actually supported byMsgConfirm. If unsupported, buttons silently fall back to defaults or throw. -
t('system.resourceManagement.delete.modelReferenced')— Cross-module key used in the model module. Fine functionally, but consider namespacing undermodel.*for maintainability and translator ownership clarity. -
useI18n({ useScope: 'global' })— Consistent with rest of app? If other components omit scope, ensure global messages include all referenced keys (common.fields.*,model.*,system.resourceManagement.*). -
Locale-change reactivity of column labels —
el-table-columnlabelbindings via:label="t(...)"will update, good. ButMkViewLayout :title="t('model.title')"— verifyMkViewLayoutre-renders on title prop change.
Optimization Suggestions
-
Extract repeated translation lookups — e.g.
t('common.fields.creator')appears twice;t('common.actions.delete')twice. Minor, but a small local helper could reduce duplication. -
Memoize
modelTypeOptionstranslation —Object.entries(...).mapruns on every locale change; acceptable, but ifMODEL_TYPE_LABELSis large, consider precomputing translated map. -
selectedProvider/selectedModelTypetype safety —ref('')works butMkTableFilterwithmode="single"may emitnull/undefined; considerref<string | undefined>(). -
Inline array literal in
v-if—['TTS','LLM',...].includes(row.model_type)allocates on every render. Hoist to aSetconstant:const PARAM_SETTING_TYPES = new Set(['TTS','LLM','IMAGE','TTI','STT','EMBEDDING']) // ...PARAM_SETTING_TYPES.has(row.model_type)
-
Test coverage — Add a test verifying that switching locale updates table headers/filters (regression guard for the i18n refactor).
-
Long
<MkTableFilter>lines — Multi-line formatting introduced is good; keep for consistency across all filters.
Summary
The diff is a clean i18n migration. Main risk points: verify MsgConfirm third-arg support, confirm global message keys exist in all locales, and double-check searchFields / options recompute on locale switch. Optional micro-optimizations noted above.
| <el-button type="primary" :loading="loading" @click="handleSubmit">{{ t('common.actions.save') }}</el-button> | ||
| </template> | ||
| </MkDrawer> | ||
| </template> |
There was a problem hiding this comment.
Review of the diff
Irregularities / potential issues
-
useI18n({ useScope: 'global' })inside<script setup>— Fine, but ensure the component is within an i18n app context; otherwiset()will warn at runtime. -
Rule messages are computed once (not reactive to locale changes) —
:rules="{ ... message: t(...) }"is evaluated on each render so this is OK for re-render, but Element Plus caches rule validation state. If the user switches language while the form is open with a visible error, the message may not update until re-validation. Minor. -
Inconsistent translation source for
model_typerule message — You usedt('model.form.type.placeholder')("请选择模型类型"/similar) as the validation message instead of a dedicatedmodel.form.type.required. Placeholder text and a validation error are semantically different keys; reuse is misleading and couples them. Add a dedicated required key. -
MODEL_TYPE_LABELSnow passed throught(label)— This assumes every value inMODEL_TYPE_LABELSis already an i18n key (e.g.model.types.llm.label). If it still contains raw Chinese strings,t()will just return them verbatim (works), but it silently breaks the convention and may emit missing-key warnings depending on config. Verify the constant was migrated to keys, or wrap conditionally. -
MsgWarning/MsgSuccesscalls now depend ontat call time — Good. But the fallback branchloadBuiltinshowsMsgWarning('usingBuiltinModels')unconditionally before checking whether built-ins were actually used; unchanged behavior, but worth confirming thatapplyBaseModelOptionssuccess/failure is what determines the warning vs. silent fallback. -
Hard-coded drawer title concatenation removed correctly, but check that
model.form.editTitleuses a named interpolation{providerName}and that other locales also have that placeholder — a missing param renders the literal{providerName}. -
Footer buttons still close via
visible = falsedirectly — unchanged; consider calling anonClosehandler if you need to reset state/icons consistently.
Optimization suggestions
- Deduplicate
t()lookups:t('common.actions.cancel'),t('common.actions.save')etc. are called per render — trivial cost, but referencingtdirectly in template is idiomatic and fine. - Extract rule objects into
computedso they react cleanly to locale:This avoids inline object recreation each render and makes rule changes testable.const nameRules = computed(() => [{ whitespace: true, required: true, message: t('model.form.name.required'), trigger: 'blur' }])
- Tooltip content lists: 9 sequential
<p>{{ t(...) }}</p>entries could be driven by av-forover acomputedarray of type descriptions (model.types.*.description) — reduces template noise and keeps ordering centralized. MkTooltip :content="t(...)"vs<template #content>inconsistency: some tooltips bindcontent, others use slot. Consider standardizing (slot supports rich content;contentis plain text).- Language switch reactivity: since
tfrom global scope is reactive, computed-based rules/titles will update automatically. Using inlinet()in:rulesprevents this because Element Plus holds the resolved string. Migrating tocomputedrules fixes point 2 above. - Sanity check: confirm all new keys (
model.form.name.*,model.form.baseModel.*,model.actions.fetchModels,model.types.*.description,common.messages.modified) exist in every locale file; missing keys will surface UI bugs only in non-default locales.
Summary
No functional regressions in the diff. Main actionable items: (a) add a dedicated model.form.type.required key instead of reusing the placeholder, (b) verify MODEL_TYPE_LABELS values are i18n keys, (c) move validation rules into computed for locale reactivity, (d) audit locale files for completeness of the new keys.
feat: locales for model of edition_1