File tree Expand file tree Collapse file tree 6 files changed +64
-0
lines changed Expand file tree Collapse file tree 6 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,12 @@ eg. `{ lazyComponent: true }`
58
58
59
59
Whether to automatically import styles.
60
60
61
+ ### defaultLocale
62
+
63
+ - Type: ` string `
64
+
65
+ Replace default locale, you can find locale list [ here] ( https://github.com/youzan/vant/tree/main/packages/vant/src/locale/lang ) .
66
+
61
67
### excludeExports
62
68
63
69
- Type: ` array `
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export default defineNuxtConfig({
5
5
modules : [ Vant ] ,
6
6
vant : {
7
7
lazyload : true ,
8
+ defaultLocale : 'en-US' ,
8
9
imports : [ 'Locale' , 'useCurrentLang' ]
9
10
}
10
11
} )
Original file line number Diff line number Diff line change 1
1
export * from './components'
2
2
export * from './imports'
3
3
export * from './lazyload'
4
+ export * from './localePlugn'
4
5
export * from './options'
5
6
export * from './styles'
6
7
export * from './transformPlugin'
Original file line number Diff line number Diff line change
1
+ import { createUnplugin } from 'unplugin'
2
+ import MagicString from 'magic-string'
3
+ import type { NuxtOptions } from '@nuxt/schema'
4
+ import { libraryName } from '../config'
5
+
6
+ interface LocalePluginOptions {
7
+ sourcemap ?: NuxtOptions [ 'sourcemap' ] [ 'client' ]
8
+ locale : string
9
+ }
10
+
11
+ export const localePlugin = createUnplugin ( ( options : LocalePluginOptions ) => {
12
+ return {
13
+ name : `${ libraryName } :locale` ,
14
+ enforce : 'pre' ,
15
+ transformInclude ( id ) {
16
+ const regExp = new RegExp ( `${ libraryName } /es/locale/index` )
17
+ return ! ! id . match ( regExp )
18
+ } ,
19
+ transform ( code , id ) {
20
+ const s = new MagicString ( code )
21
+
22
+ s . replaceAll ( 'zh-CN' , options . locale )
23
+
24
+ if ( s . hasChanged ( ) ) {
25
+ return {
26
+ code : s . toString ( ) ,
27
+ map : options . sourcemap
28
+ ? s . generateMap ( { source : id , includeContent : true } )
29
+ : undefined
30
+ }
31
+ }
32
+ }
33
+ }
34
+ } )
Original file line number Diff line number Diff line change 6
6
resolveLazyload ,
7
7
resolveOptions ,
8
8
resolveStyles ,
9
+ localePlugin ,
9
10
transformPlugin
10
11
} from './core/index'
11
12
import type { Options } from './types'
@@ -36,6 +37,13 @@ export default defineNuxtModule<Partial<Options>>({
36
37
transformStyles : name => resolveStyles ( options , name )
37
38
} )
38
39
)
40
+
41
+ if ( options . defaultLocale && options . defaultLocale !== 'zh-CN' ) {
42
+ config . plugins . push ( localePlugin . vite ( {
43
+ sourcemap : nuxt . options . sourcemap [ mode ] ,
44
+ locale : options . defaultLocale
45
+ } ) )
46
+ }
39
47
} )
40
48
41
49
nuxt . hook ( 'webpack:config' , ( configs ) => {
@@ -51,6 +59,13 @@ export default defineNuxtModule<Partial<Options>>({
51
59
transformStyles : name => resolveStyles ( options , name )
52
60
} )
53
61
)
62
+
63
+ if ( options . defaultLocale && options . defaultLocale !== 'zh-CN' ) {
64
+ config . plugins . push ( localePlugin . webpack ( {
65
+ sourcemap : nuxt . options . sourcemap [ mode ] ,
66
+ locale : options . defaultLocale
67
+ } ) )
68
+ }
54
69
} )
55
70
} )
56
71
}
Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ export interface Options extends TransformOptions {
27
27
* @default true
28
28
*/
29
29
importStyle : boolean
30
+ /**
31
+ * Replace default locale, you can find locale list [here](https://github.com/youzan/vant/tree/main/packages/vant/src/locale/lang).
32
+ *
33
+ * @default 'zh-CN'
34
+ * @example 'en-US'
35
+ */
36
+ defaultLocale ?: string
30
37
/**
31
38
* Exclude exports from Vant that are not component content.
32
39
*
You can’t perform that action at this time.
0 commit comments