fix: some i18n error

This commit is contained in:
gchust 2025-06-28 20:46:50 +08:00
parent 1f95f6d5d0
commit 05f5530232
19 changed files with 32 additions and 28 deletions

View File

@ -27,8 +27,7 @@ export const refreshOnCompleteAction = {
async handler(ctx, params) {
if (params.enable) {
await ctx.extra.currentResource.refresh();
const t = ctx.globals.flowEngine.translate;
ctx.globals.message.success(t('Data refreshed successfully'));
ctx.globals.message.success(ctx.model.translate('Data refreshed successfully'));
}
},
};

View File

@ -35,7 +35,7 @@ BulkDeleteActionModel.registerFlow({
},
delete: {
async handler(ctx, params) {
const t = ctx.globals.flowEngine.translate;
const t = ctx.model.translate;
if (!ctx.shared?.currentBlockModel?.resource) {
ctx.globals.message.error(t('No resource selected for deletion'));
return;

View File

@ -52,7 +52,7 @@ BulkEditActionModel.registerFlow({
};
},
async handler(ctx, params) {
const t = ctx.globals.flowEngine.translate;
const t = ctx.model.translate;
if (!ctx.shared?.currentBlockModel?.resource) {
ctx.globals.message.error(t('No resource selected for bulk edit'));
return;

View File

@ -35,7 +35,7 @@ DeleteActionModel.registerFlow({
},
delete: {
async handler(ctx, params) {
const t = ctx.globals.flowEngine.translate;
const t = ctx.model.translate;
if (!ctx.shared?.currentBlockModel?.resource) {
ctx.globals.message.error(t('No resource selected for deletion'));
return;

View File

@ -20,7 +20,7 @@ const FilterContent: FC<{ value: any }> = (props) => {
const currentBlockModel = modelInstance.ctx.shared.currentBlockModel as DataBlockModel;
const fields = currentBlockModel.collection.getFields();
const ignoreFieldsNames = modelInstance.props.ignoreFieldsNames || [];
const t = modelInstance.flowEngine.translate;
const t = modelInstance.translate;
return (
<>
@ -44,7 +44,7 @@ export class FilterActionModel extends GlobalActionModel {
defaultProps: any = {
type: 'default',
children: tval('Filter'),
title: tval('Filter'),
icon: 'FilterOutlined',
filterValue: { $and: [] },
ignoreFieldsNames: [],

View File

@ -31,7 +31,7 @@ RefreshActionModel.registerFlow({
steps: {
refresh: {
async handler(ctx, params) {
const t = ctx.globals.flowEngine.translate;
const t = ctx.model.translate;
const currentResource = ctx.shared?.currentBlockModel?.resource;
if (!currentResource) {
ctx.globals.message.error(t('No resource selected for refresh'));

View File

@ -69,7 +69,7 @@ export class GridModel extends FlowModel<GridModelStructure> {
}
render() {
const t = this.flowEngine.translate.bind(this.flowEngine);
const t = this.translate;
console.log('GridModel render', JSON.stringify(this.props.rows, null, 2), this.props.sizes);
return (
<div style={{ padding: 16 }}>

View File

@ -65,7 +65,7 @@ CalendarBlockModel.registerFlow({
step1: {
handler(ctx, params) {
console.log('ctx.extra.event', ctx.extra.event);
const t = ctx.model.flowEngine.translate;
const t = ctx.model.translate;
Modal.info({
title: t('Event selected'),
content: (
@ -96,7 +96,7 @@ CalendarBlockModel.registerFlow({
step1: {
handler(ctx, params) {
console.log('ctx.extra.event', ctx.extra.event);
const t = ctx.model.flowEngine.translate;
const t = ctx.model.translate;
Modal.info({
title: t('Double click'),
content: (

View File

@ -17,7 +17,7 @@ export class FormActionModel extends ActionModel {}
export class FormSubmitActionModel extends FormActionModel {
defaultProps: ButtonProps = {
children: tval('Submit'),
title: tval('Submit'),
type: 'primary',
htmlType: 'submit',
};

View File

@ -64,7 +64,7 @@ export class TableActionsColumnModel extends FlowModel {
},
]}
>
<Space>{this.props.title || tval('Actions')}</Space>
<Space>{this.props.title || this.flowEngine.translate('Actions')}</Space>
</FlowsFloatContextMenu>
),
render: this.render(),

View File

@ -261,7 +261,7 @@ export class TabulatorModel extends DataBlockModel<S> {
<FlowModelRenderer model={action} showFlowSettings sharedContext={{ currentBlockModel: this }} />
))}
<AddActionButton model={this} subModelBaseClass="GlobalActionModel" subModelKey="actions">
<Button icon={<SettingOutlined />}>{this.ctx.globals.translate('Configure actions')}</Button>
<Button icon={<SettingOutlined />}>{this.translate('Configure actions')}</Button>
</AddActionButton>
</Space>
<div ref={this.tabulatorRef} />

View File

@ -16,7 +16,7 @@ import { FilterFormActionModel } from './FilterFormActionModel';
export class FilterFormSubmitActionModel extends FilterFormActionModel {
defaultProps: ButtonProps = {
children: tval('Filter'),
title: tval('Filter'),
type: 'primary',
};
}

View File

@ -233,10 +233,12 @@ export const DefaultSettingsIcon: React.FC<DefaultSettingsIconProps> = ({
// 如果step使用了action检查action是否有uiSchema
let hasActionUiSchema = false;
let stepTitle = actionStep.title;
if (actionStep.use) {
try {
const action = targetModel.flowEngine?.getAction?.(actionStep.use);
hasActionUiSchema = action && action.uiSchema != null;
stepTitle = stepTitle || action.title;
} catch (error) {
console.warn(t('Failed to get action {{action}}', { action: actionStep.use }), ':', error);
}
@ -255,7 +257,7 @@ export const DefaultSettingsIcon: React.FC<DefaultSettingsIconProps> = ({
stepKey,
step: actionStep,
uiSchema: mergedUiSchema,
title: t(actionStep.title) || stepKey,
title: t(stepTitle) || stepKey,
modelKey, // 添加模型标识
};
})

View File

@ -306,7 +306,7 @@ const openRequiredParamsStepFormDialog = async ({
// 创建FormDialog
const formDialog = FormDialog(
{
title: dialogTitle,
title: dialogTitle || t('Step Parameter Configuration'),
width: dialogWidth,
footer: null, // 移除默认的底部按钮,使用自定义的导航按钮
destroyOnClose: true,

View File

@ -53,9 +53,7 @@ const openStepSettingsDialog = async ({
throw new Error(t('Step with key {{stepKey}} not found', { stepKey }));
}
const title =
dialogTitle ||
(step ? `${step.title || stepKey} - ${t('Configuration')}` : `${t('Step Configuration')} - ${stepKey}`);
let title = step.title;
// 创建参数解析上下文
const paramsContext = {
@ -76,6 +74,7 @@ const openStepSettingsDialog = async ({
actionUiSchema = action.uiSchema;
}
actionDefaultParams = action.defaultParams || {};
title = title || action.title;
}
// 解析动态 uiSchema
@ -132,7 +131,7 @@ const openStepSettingsDialog = async ({
// 创建FormDialog
const formDialog = FormDialog(
{
title,
title: dialogTitle || `${t(title)} - ${t('Configuration')}`,
width: dialogWidth,
okText: t('OK'),
cancelText: t('Cancel'),

View File

@ -54,9 +54,7 @@ const openStepSettingsDrawer = async ({
throw new Error(t('Step with key {{stepKey}} not found', { stepKey }));
}
const title =
drawerTitle ||
(step ? `${step.title || stepKey} - ${t('Configuration')}` : `${t('Step Configuration')} - ${stepKey}`);
let title = step.title;
// 创建参数解析上下文
const paramsContext = {
@ -76,6 +74,7 @@ const openStepSettingsDrawer = async ({
actionUiSchema = action.uiSchema;
}
actionDefaultParams = action.defaultParams || {};
title = title || action.title;
}
// 解析动态 uiSchema
@ -240,7 +239,7 @@ const openStepSettingsDrawer = async ({
// 打开抽屉
const drawerRef = drawer.open({
title,
title: drawerTitle || `${t(title)} - ${t('Configuration')}`,
width: drawerWidth,
content: <DrawerContent />,
onClose: () => {

View File

@ -84,7 +84,7 @@ const LazyDropdown: React.FC<Omit<DropdownProps, 'menu'> & { menu: LazyDropdownM
const dropdownMaxHeight = useNiceDropdownMaxHeight([menuVisible]);
const [isSearching, setIsSearching] = useState(false);
const searchTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const t = model.flowEngine.translate.bind(model.flowEngine);
const t = model.translate;
// 清理定时器,避免内存泄露
useEffect(() => {

View File

@ -14,6 +14,7 @@ import {
ActionDefinition,
ActionOptions,
CreateModelOptions,
FlowContext,
FlowDefinition,
IFlowModelRepository,
ModelConstructor,
@ -37,7 +38,7 @@ export class FlowEngine {
private modelInstances: Map<string, any> = new Map();
/** @public Stores flow settings including components and scopes for formily settings. */
public flowSettings: FlowSettings = new FlowSettings();
context: Record<string, any> = {};
context: FlowContext['globals'] = {} as FlowContext['globals'];
private modelRepository: IFlowModelRepository | null = null;
private _applyFlowCache = new Map<string, ApplyFlowCacheEntry>();

View File

@ -397,7 +397,7 @@ export class FlowModel<Structure extends { parent?: any; subModels?: any } = Def
console[level.toLowerCase()](logMessage, logMeta);
};
const globalContexts = currentFlowEngine.getContext() || {};
const globalContexts = currentFlowEngine.getContext();
const flowContext: FlowContext<this> = {
exit: () => {
throw new FlowExitException(flowKey, this.uid);
@ -902,6 +902,10 @@ export class FlowModel<Structure extends { parent?: any; subModels?: any } = Def
};
}
get translate() {
return this.flowEngine.translate.bind(this.flowEngine);
}
public setSharedContext(ctx: Record<string, any>) {
this._sharedContext = { ...this._sharedContext, ...ctx };
}