Skip to content
This repository was archived by the owner on Jan 23, 2022. It is now read-only.

Commit b7302a7

Browse files
committed
feat: added element-plus ^1.0.2-beta.59 i18n support
closes #19
1 parent 9f5a3e2 commit b7302a7

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

generator/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
module.exports = (api, opts, rootOptions) => {
1+
module.exports = (api, opts) => {
22
const utils = require('./utils')(api)
33

44
api.extendPackage({
55
dependencies: {
6-
'element-plus': '^1.0.2-beta.28'
6+
'element-plus': '^1.0.2-beta.71'
77
}
88
})
99

10-
api.injectImports(api.entryFile, `import installElementPlus from './plugins/element'`)
10+
api.injectImports(api.entryFile, [
11+
`import installElementPlus from './plugins/element.js'`,
12+
`import locale from 'element-plus/lib/locale/lang/${opts.lang}.js'`
13+
])
1114

1215
api.render({
1316
'./src/plugins/element.js': './templates/src/plugins/element.js',
@@ -42,7 +45,15 @@ module.exports = (api, opts, rootOptions) => {
4245

4346
if (renderIndex >= 0) {
4447
const renderContent = lines[renderIndex]
45-
lines[renderIndex] = `const app = createApp(App)`
48+
lines[renderIndex] = `const app = createApp({
49+
render() {
50+
return (
51+
<ElConfigProvider locale={locale}>
52+
<App />
53+
</ElConfigProvider>
54+
)
55+
},
56+
})`
4657
lines[renderIndex + 1] = `installElementPlus(app)`
4758
lines[renderIndex + 2] = renderContent.replace('createApp\(App\)','app')
4859

generator/templates/src/plugins/element.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,15 @@ import '../element-variables.scss'
55
<%_ } else { _%>
66
import 'element-plus/lib/theme-chalk/index.css'
77
<%_ } _%>
8-
<%_ if (options.lang !== 'en') { _%>
9-
import locale from 'element-plus/lib/locale/lang/<%= options.lang %>'
10-
<%_ } _%>
118
<%_ } else { _%>
12-
import { ElButton } from 'element-plus'
13-
<%_ if (options.lang !== 'en') { _%>
14-
import lang from 'element-plus/lib/locale/lang/<%= options.lang %>'
15-
import locale from 'element-plus/lib/locale'
16-
<%_ }} _%>
9+
import { ElButton, ElConfigProvider } from 'element-plus'
10+
<%_ } _%>
1711

1812
export default (app) => {
1913
<%_ if (options.import === 'full') { _%>
20-
<%_ if (options.lang !== 'en') { _%>
21-
app.use(ElementPlus, { locale })
22-
<%_ } else { _%>
2314
app.use(ElementPlus)
24-
<%_ } _%>
2515
<%_ } else { _%>
26-
<%_ if (options.lang !== 'en') { _%>
27-
locale.use(lang)
28-
<%_ } _%>
2916
app.use(ElButton)
17+
app.use(ElConfigProvider)
3018
<%_ } _%>
3119
}

0 commit comments

Comments
 (0)