Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unable to switch between multiple languages #39

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}