chore: editor开发态国际化 (#7903)

* chore: editor开发态国际化

* chore: editor开发态国际化

* 插件不是用ts写的,没有声明

---------

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
This commit is contained in:
qkiroc 2023-08-22 15:25:08 +08:00 committed by GitHub
parent 866d3412b6
commit 31544b47cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 10 deletions

40
i18nConfig.ts Normal file
View File

@ -0,0 +1,40 @@
export default {
entry: {
dir: './packages/amis-editor-core/src'
},
file: {
test: /.*(ts|tsx|js|jsx)$/
},
ignore: {
list: [
'packages/**/locale/*',
'packages/amis/*',
'packages/amis-ui/*',
'packages/amis-core/*',
'packages/amis-formula/*',
'packages/**/examples/*'
]
},
importInfo: {
source: 'i18n-runtime',
imported: 'i18n',
local: '_i18n'
},
i18nModule: 'i18n-runtime',
languages: [
{
name: 'en-US',
path: [
'./packages/amis-editor-core/src/locale',
'./packages/amis-editor/src/locale'
]
},
{
name: 'zh-CN',
path: [
'./packages/amis-editor-core/src/locale',
'./packages/amis-editor/src/locale'
]
}
]
};

View File

@ -700,13 +700,19 @@ export default class AMisSchemaEditor extends React.Component<any, any> {
<div className="Editor-header-actions">
<ShortcutKey />
{/* <Select
className="margin-left-space "
options={editorLanguages}
value={curLanguage}
clearable={false}
onChange={(e: any) => this.changeLocale(e.value)}
/> */}
{
// @ts-ignore
// vite编译时替换
__editor_i18n ? (
<Select
className="margin-left-space "
options={editorLanguages}
value={curLanguage}
clearable={false}
onChange={(e: any) => this.changeLocale(e.value)}
/>
) : null
}
{i18nEnabled && (
<Button

View File

@ -8,10 +8,36 @@ import fis3 from './scripts/fis3plugin';
import markdown from './scripts/markdownPlugin';
import mockApi from './scripts/mockApiPlugin';
import transformMobileHtml from './scripts/transformMobileHtml';
//@ts-ignore
import i18nPlugin from 'plugin-react-i18n';
import i18nConfig from './i18nConfig';
var I18N = process.env.I18N;
var PROXY_THEME = process.env.PROXY_THEME
? [
{
find: 'amis-theme-editor/lib/renderers.css',
replacement: path.resolve(
__dirname,
'../editor/packages/amis-theme-editor/src/renderers/style/_index.scss'
)
},
{
find: 'amis-theme-editor/lib',
replacement: path.resolve(
__dirname,
'../editor/packages/amis-theme-editor/src'
)
}
]
: [];
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
I18N && i18nPlugin(i18nConfig),
fis3(),
markdown(),
mockApi(),
@ -34,8 +60,11 @@ export default defineConfig({
dimensions: false
}
}),
monacoEditorPlugin({})
],
monacoEditorPlugin({}),
replace({
__editor_i18n: !!I18N
})
].filter(n => n),
optimizeDeps: {
include: ['amis-formula/lib/doc'],
exclude: ['amis-core', 'amis-formula', 'amis', 'amis-ui'],
@ -97,6 +126,6 @@ export default defineConfig({
find: 'office-viewer',
replacement: path.resolve(__dirname, './packages/office-viewer/src')
}
]
].concat(PROXY_THEME)
}
});