chore: jssdk 中使用代码编辑器在不同的 locale 下加载编辑器对应的语言文件 Close: #8880 (#9160)

This commit is contained in:
liaoxuezhi 2023-12-19 14:25:33 +08:00 committed by GitHub
parent 57ad94a136
commit 4aed7004ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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': {

View File

@ -201,6 +201,9 @@ export class Editor extends React.Component<EditorProps, EditorState> {
}
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));
}