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)); }