Skip to content

Commit 6b5b424

Browse files
huxingyi1997JackLian
authored andcommitted
feat: add i18n for plugin-schema
1 parent bb58130 commit 6b5b424

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

packages/plugin-schema/src/editor.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ import { useState, useRef, useCallback, useEffect, useLayoutEffect } from 'react
33
import MonacoEditor from '@alilc/lowcode-plugin-base-monaco-editor';
44

55
import { Dialog, Message, Button } from '@alifd/next';
6-
import { IPublicApiProject, IPublicApiSkeleton, IPublicEnumTransformStage } from '@alilc/lowcode-types';
6+
import { IPublicEnumTransformStage, IPublicModelPluginContext } from '@alilc/lowcode-types';
77
import { IEditorInstance } from '@alilc/lowcode-plugin-base-monaco-editor/lib/helper';
88

99
interface PluginCodeDiffProps {
10-
project: IPublicApiProject;
11-
skeleton: IPublicApiSkeleton;
10+
pluginContext: IPublicModelPluginContext;
1211
// 是否显示项目级 schema
1312
showProjectSchema: boolean;
1413
}
1514

16-
export default function PluginSchema({ project, skeleton, showProjectSchema = false }: PluginCodeDiffProps) {
15+
export default function PluginSchema({ pluginContext, showProjectSchema = false }: PluginCodeDiffProps) {
16+
const { project, skeleton } = pluginContext;
17+
1718
const [editorSize, setEditorSize] = useState({ width: 0, height: 0 });
1819
const [schemaValue, setSchemaValue] = useState(() => {
1920
const schema = project.exportSchema(IPublicEnumTransformStage.Save);
@@ -82,7 +83,7 @@ export default function PluginSchema({ project, skeleton, showProjectSchema = fa
8283
onClick={onSave}
8384
style={{ position: 'absolute', right: 68, zIndex: 100, top: -38 }}
8485
>
85-
保存 Schema
86+
{pluginContext.intl('Save Schema')}
8687
</Button>
8788
<MonacoEditor
8889
height={editorSize.height}

packages/plugin-schema/src/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import * as React from 'react';
22
import { IPublicModelPluginContext } from '@alilc/lowcode-types';
33
import PluginSchema from './editor';
4+
import { enUS, zhCN } from './locale';
45

56
const plugin = (ctx: IPublicModelPluginContext, options: any) => {
67
return {
78
// 插件的初始化函数,在引擎初始化之后会立刻调用
89
init() {
10+
const { intl, intlNode, getLocale } = ctx.common.utils.createIntl({
11+
'en-US': enUS,
12+
'zh-CN': zhCN,
13+
});
14+
ctx.intl = intl;
15+
ctx.intlNode = intlNode;
16+
ctx.getLocale = getLocale;
917
const isProjectSchema = (options && options['isProjectSchema']) === true;
1018

1119
// 往引擎增加面板
@@ -23,8 +31,7 @@ const plugin = (ctx: IPublicModelPluginContext, options: any) => {
2331
},
2432
content: () => (
2533
<PluginSchema
26-
project={ctx.project}
27-
skeleton={ctx.skeleton}
34+
pluginContext={ctx}
2835
showProjectSchema={isProjectSchema}
2936
/>
3037
),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Save Schema": "Save Schema"
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import enUS from './en-US.json';
2+
import zhCN from './zh-CN.json';
3+
4+
export { enUS, zhCN };
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Save Schema": "保存 Schema"
3+
}

packages/plugin-schema/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"moduleResolution": "node",
99
"lib": ["DOM", "ES6"],
1010
"noImplicitAny": false,
11-
"skipLibCheck": true
11+
"skipLibCheck": true,
12+
"resolveJsonModule": true,
13+
"allowSyntheticDefaultImports": true,
1214
},
1315
"include": [
1416
"src/**/*.ts",

0 commit comments

Comments
 (0)