Skip to content

Commit 1c4e56f

Browse files
authored
fix: unable to switch between multiple languages (#39)
1 parent 436d877 commit 1c4e56f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

playground/app.vue

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<script setup lang="ts">
2+
import enUS from 'vant/es/locale/lang/en-US'
3+
import zhCN from 'vant/es/locale/lang/zh-CN'
4+
5+
const lang = useCurrentLang()
6+
27
const showCalendar = ref(false)
38
const showPopup = ref(false)
49
const showCascader = ref(false)
@@ -41,6 +46,13 @@ const onConfirm = (value: Date) => {
4146
const showImage = (index: number) => {
4247
showImagePreview({ images: imageList, startPosition: index })
4348
}
49+
const changeLocale = () => {
50+
if (lang.value === 'en-US') {
51+
Locale.use('zh-CN', zhCN)
52+
} else {
53+
Locale.use('en-US', enUS)
54+
}
55+
}
4456
4557
onMounted(() => {
4658
showNotify('通知内容')
@@ -87,6 +99,9 @@ onMounted(() => {
8799
<LazyVanButton type="success" @click="openFloatingPanel">
88100
Open Floating Panel
89101
</LazyVanButton>
102+
<van-button type="warning" @click="changeLocale">
103+
i18n
104+
</van-button>
90105
</van-col>
91106
<van-col span="4">
92107
<van-icon name="chat-o" />
@@ -120,6 +135,7 @@ onMounted(() => {
120135
弹出默认键盘
121136
</van-cell>
122137
</van-cell-group>
138+
<van-pagination :total-items="24" :items-per-page="5" />
123139

124140
<van-collapse v-model="activeNames">
125141
<van-collapse-item title="标题1" name="1">

playground/nuxt.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Vant from '..'
44
export default defineNuxtConfig({
55
modules: [Vant],
66
vant: {
7-
lazyload: true
7+
lazyload: true,
8+
imports: ['Locale', 'useCurrentLang']
89
}
910
})

src/core/options.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { libraryName } from '../config'
33

44
export function resolveOptions () {
55
const nuxt = useNuxt()
6-
const regExp = new RegExp(`${libraryName}/es/.*/style/index.mjs`)
76

8-
nuxt.options.build.transpile.push(regExp)
7+
nuxt.options.build.transpile.push(libraryName)
8+
nuxt.options.vite.optimizeDeps ??= {}
9+
nuxt.options.vite.optimizeDeps.exclude ??= []
10+
nuxt.options.vite.optimizeDeps.exclude.push(libraryName)
911
}

0 commit comments

Comments
 (0)