From 4aed7004ca3406af89da28a938bcb6300ea98b1b Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Tue, 19 Dec 2023 14:25:33 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20jssdk=20=E4=B8=AD=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=BC=96=E8=BE=91=E5=99=A8=E5=9C=A8=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=9A=84=20locale=20=E4=B8=8B=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E5=99=A8=E5=AF=B9=E5=BA=94=E7=9A=84=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E6=96=87=E4=BB=B6=20Close:=20#8880=20(#9160)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/loadMonacoEditor.ts | 13 ++++++++++++- packages/amis-ui/src/components/Editor.tsx | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/loadMonacoEditor.ts b/examples/loadMonacoEditor.ts index 9f07a26a5..a2e9fbe0c 100644 --- a/examples/loadMonacoEditor.ts +++ b/examples/loadMonacoEditor.ts @@ -19,10 +19,21 @@ function filterUrl(url: string) { } function onLoad(req: any, callback: (result: any) => void) { + const locale = + ((window as any).__amis_monaco_editor_locale && + ( + { + 'zh-CN': 'zh-cn', + 'en-US': '', + 'de-DE': 'de' + } as any + )[(window as any).__amis_monaco_editor_locale]) || + ''; + const config = { 'vs/nls': { availableLanguages: { - '*': 'zh-cn' + '*': locale } }, 'paths': { diff --git a/packages/amis-ui/src/components/Editor.tsx b/packages/amis-ui/src/components/Editor.tsx index 13ffd1428..95ce216b0 100644 --- a/packages/amis-ui/src/components/Editor.tsx +++ b/packages/amis-ui/src/components/Editor.tsx @@ -201,6 +201,9 @@ export class Editor extends React.Component { } loadMonaco() { + // 由于 require.config({'vs/nls': { availableLanguages: { '*': 'xxxx' }}}) 只能在初始化之前设置有用,所以这里只能用全局变量的方式来设置。 + // 另外此方式只是针对 jssdk 和平台有效,对于其他方式还需要再想想。 + (window as any).__amis_monaco_editor_locale = this.props.locale; import('monaco-editor').then(monaco => this.initMonaco(monaco)); }