Skip to content

Commit

Permalink
chore: editor开发态国际化
Browse files Browse the repository at this point in the history
  • Loading branch information
qkiroc committed Aug 22, 2023
1 parent d66a7cd commit 2800dfd
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 10 deletions.
40 changes: 40 additions & 0 deletions i18nConfig.ts
Original file line number Diff line number Diff line change
@@ -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'
]
}
]
};
20 changes: 13 additions & 7 deletions packages/amis-editor/examples/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 34 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,38 @@ import fis3 from './scripts/fis3plugin';
import markdown from './scripts/markdownPlugin';
import mockApi from './scripts/mockApiPlugin';
import transformMobileHtml from './scripts/transformMobileHtml';
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'
)
}
]
: [];

if (I18N) {
}

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
I18N && i18nPlugin(i18nConfig),

fis3(),
markdown(),
mockApi(),
Expand All @@ -34,8 +62,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'],
Expand Down Expand Up @@ -97,6 +128,6 @@ export default defineConfig({
find: 'office-viewer',
replacement: path.resolve(__dirname, './packages/office-viewer/src')
}
]
].concat(PROXY_THEME)
}
});

0 comments on commit 2800dfd

Please sign in to comment.