fix(react-simulator-renderer): fix missing i18n of customCreateElement

This commit is contained in:
haoziqaq 2023-01-17 18:58:34 +08:00 committed by 林熠
parent 17a0f72457
commit 5c6572e302
4 changed files with 35 additions and 4 deletions

View File

@ -0,0 +1,4 @@
{
"Drag and drop components or templates here": "Drag and drop components or templates here",
"Locked elements and child elements cannot be edited": "Locked elements and child elements cannot be edited"
}

View File

@ -0,0 +1,21 @@
import { createElement } from 'react';
import enUS from './en-US.json';
import zhCN from './zh-CN.json';
const instance: Record<string, Record<string, string>> = {
'zh-CN': zhCN as Record<string, string>,
'en-US': enUS as Record<string, string>,
};
export function createIntl(locale: string = 'zh-CN') {
const intl = (id: string) => {
return instance[locale][id];
};
const intlNode = (id: string) => createElement('span', instance[locale][id]);
return {
intl,
intlNode,
};
}

View File

@ -0,0 +1,4 @@
{
"Drag and drop components or templates here": "拖拽组件或模板到这里",
"Locked elements and child elements cannot be edited": "锁定元素及子元素无法编辑"
}

View File

@ -10,6 +10,7 @@ import { SimulatorRendererContainer, DocumentInstance } from './renderer';
import { host } from './host'; import { host } from './host';
import { isRendererDetached } from './utils/misc'; import { isRendererDetached } from './utils/misc';
import './renderer.less'; import './renderer.less';
import { createIntl } from './locale';
// patch cloneElement avoid lost keyProps // patch cloneElement avoid lost keyProps
const originCloneElement = window.React.cloneElement; const originCloneElement = window.React.cloneElement;
@ -130,6 +131,7 @@ class Renderer extends Component<{
documentInstance: DocumentInstance; documentInstance: DocumentInstance;
}> { }> {
startTime: number | null = null; startTime: number | null = null;
schemaChangedSymbol = false;
componentDidUpdate() { componentDidUpdate() {
this.recordTime(); this.recordTime();
@ -152,8 +154,6 @@ class Renderer extends Component<{
this.recordTime(); this.recordTime();
} }
schemaChangedSymbol = false;
getSchemaChangedSymbol = () => { getSchemaChangedSymbol = () => {
return this.schemaChangedSymbol; return this.schemaChangedSymbol;
}; };
@ -172,6 +172,8 @@ class Renderer extends Component<{
if (!container.autoRender || isRendererDetached()) return null; if (!container.autoRender || isRendererDetached()) return null;
const { intl } = createIntl(locale);
return ( return (
<LowCodeRenderer <LowCodeRenderer
locale={locale} locale={locale}
@ -206,12 +208,12 @@ class Renderer extends Component<{
(children == null || (Array.isArray(children) && !children.length)) && (children == null || (Array.isArray(children) && !children.length)) &&
(!viewProps.style || Object.keys(viewProps.style).length === 0) (!viewProps.style || Object.keys(viewProps.style).length === 0)
) { ) {
let defaultPlaceholder = '拖拽组件或模板到这里'; let defaultPlaceholder = intl('Drag and drop components or templates here');
const lockedNode = getClosestNode(leaf, (node) => { const lockedNode = getClosestNode(leaf, (node) => {
return node?.getExtraProp('isLocked')?.getValue() === true; return node?.getExtraProp('isLocked')?.getValue() === true;
}); });
if (lockedNode) { if (lockedNode) {
defaultPlaceholder = '锁定元素及子元素无法编辑'; defaultPlaceholder = intl('Locked elements and child elements cannot be edited');
} }
children = ( children = (
<div className={cn('lc-container-placeholder', { 'lc-container-locked': !!lockedNode })} style={viewProps.placeholderStyle}> <div className={cn('lc-container-placeholder', { 'lc-container-locked': !!lockedNode })} style={viewProps.placeholderStyle}>