!9 修复微信小程序国际化问题

Merge pull request !9 from wyl86/i18n
This commit is contained in:
菲鸽 2024-06-19 09:30:41 +00:00 committed by Gitee
commit ed8d1b6e67
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 27 additions and 0 deletions

View File

@ -1,8 +1,25 @@
<script setup lang="ts"> <script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app' import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { useI18n } from 'vue-i18n'
import { tabBar } from '@/pages.json'
onLaunch(() => { onLaunch(() => {
console.log('App Launch') console.log('App Launch')
// #ifdef MP-WEIXIN
const setTabbarText = () => {
const { t } = useI18n()
const tabbarTexts = tabBar.list.map((item) => item.text.replace(/(^%|%$)/g, ''))
tabbarTexts.forEach((transKey: string, index: number) => {
uni.setTabBarItem({
index,
text: t(transKey),
})
})
}
// fix api tabbar text
setTabbarText()
uni.onLocaleChange(setTabbarText)
// #endif
}) })
onShow(() => { onShow(() => {
console.log('App Show') console.log('App Show')

View File

@ -44,6 +44,16 @@
<script lang="ts" setup> <script lang="ts" setup>
import i18n, { t } from '@/locale/index' import i18n, { t } from '@/locale/index'
import { testI18n } from '@/utils/i18n' import { testI18n } from '@/utils/i18n'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
onLoad(() => {
// #ifdef MP-WEIXIN
// fix api
uni.setNavigationBarTitle({ title: t('app.name') })
// #endif
})
const current = ref(uni.getLocale()) const current = ref(uni.getLocale())
const user = { name: '张三', detail: { height: 178, weight: '75kg' } } const user = { name: '张三', detail: { height: 178, weight: '75kg' } }