Skip to content

Commit

Permalink
fix: unable to switch between multiple languages (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolking authored Aug 25, 2024
1 parent 436d877 commit 1c4e56f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
16 changes: 16 additions & 0 deletions playground/app.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<script setup lang="ts">
import enUS from 'vant/es/locale/lang/en-US'
import zhCN from 'vant/es/locale/lang/zh-CN'
const lang = useCurrentLang()
const showCalendar = ref(false)
const showPopup = ref(false)
const showCascader = ref(false)
Expand Down Expand Up @@ -41,6 +46,13 @@ const onConfirm = (value: Date) => {
const showImage = (index: number) => {
showImagePreview({ images: imageList, startPosition: index })
}
const changeLocale = () => {
if (lang.value === 'en-US') {
Locale.use('zh-CN', zhCN)
} else {
Locale.use('en-US', enUS)
}
}
onMounted(() => {
showNotify('通知内容')
Expand Down Expand Up @@ -87,6 +99,9 @@ onMounted(() => {
<LazyVanButton type="success" @click="openFloatingPanel">
Open Floating Panel
</LazyVanButton>
<van-button type="warning" @click="changeLocale">
i18n
</van-button>
</van-col>
<van-col span="4">
<van-icon name="chat-o" />
Expand Down Expand Up @@ -120,6 +135,7 @@ onMounted(() => {
弹出默认键盘
</van-cell>
</van-cell-group>
<van-pagination :total-items="24" :items-per-page="5" />

<van-collapse v-model="activeNames">
<van-collapse-item title="标题1" name="1">
Expand Down
3 changes: 2 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Vant from '..'
export default defineNuxtConfig({
modules: [Vant],
vant: {
lazyload: true
lazyload: true,
imports: ['Locale', 'useCurrentLang']
}
})
6 changes: 4 additions & 2 deletions src/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { libraryName } from '../config'

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

nuxt.options.build.transpile.push(regExp)
nuxt.options.build.transpile.push(libraryName)
nuxt.options.vite.optimizeDeps ??= {}
nuxt.options.vite.optimizeDeps.exclude ??= []
nuxt.options.vite.optimizeDeps.exclude.push(libraryName)
}

0 comments on commit 1c4e56f

Please # to comment.