2024-01-29 14:48:07 +08:00
|
|
|
|
<route lang="json">
|
|
|
|
|
{
|
|
|
|
|
"style": {
|
|
|
|
|
"navigationBarTitleText": "%app.name%"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</route>
|
2024-01-29 18:59:17 +08:00
|
|
|
|
|
2024-01-29 19:14:01 +08:00
|
|
|
|
<template>
|
2024-01-29 19:35:37 +08:00
|
|
|
|
<view class="center flex-col mt-6">
|
2024-03-03 15:34:08 +08:00
|
|
|
|
<view class="text-red-500 p-4 leading-6">
|
|
|
|
|
经过我的测试发现,小程序里面会有2处BUG:
|
2024-05-04 14:30:00 +08:00
|
|
|
|
<view>
|
|
|
|
|
<text class="line-through">1. 页面标题多语言不生效</text>
|
|
|
|
|
<text class="ml-2 text-green-500">已解决</text>
|
|
|
|
|
</view>
|
|
|
|
|
<view>
|
|
|
|
|
<text class="line-through">2. 多语言传递的参数不生效,如下 heavy</text>
|
|
|
|
|
<text class="ml-2 text-green-500">已解决</text>
|
|
|
|
|
</view>
|
2024-03-03 15:34:08 +08:00
|
|
|
|
</view>
|
2024-01-29 19:35:37 +08:00
|
|
|
|
<view class="text-green-500">多语言测试</view>
|
|
|
|
|
<view class="m-4">{{ $t('app.name') }}</view>
|
2024-03-03 15:34:08 +08:00
|
|
|
|
<view class="m-4">{{ $t('weight', { heavy: 100 }) }}</view>
|
2024-06-16 15:21:44 +08:00
|
|
|
|
<view class="m-4">{{ formatString(translate('detail'), 175, 60) }}</view>
|
2024-04-25 16:18:14 +08:00
|
|
|
|
<view class="m-4">
|
2024-05-04 10:59:10 +08:00
|
|
|
|
{{ formatI18n(translate('introduction'), user) }}
|
2024-04-25 16:18:14 +08:00
|
|
|
|
</view>
|
2024-01-29 19:35:37 +08:00
|
|
|
|
|
2024-04-02 21:20:40 +08:00
|
|
|
|
<view class="text-green-500 mt-12">切换语言</view>
|
2024-01-29 19:35:37 +08:00
|
|
|
|
<view class="uni-list">
|
|
|
|
|
<radio-group @change="radioChange" class="radio-group">
|
|
|
|
|
<label class="uni-list-cell uni-list-cell-pd" v-for="item in languages" :key="item.value">
|
|
|
|
|
<view>
|
|
|
|
|
<radio :value="item.value" :checked="item.value === current" />
|
|
|
|
|
</view>
|
|
|
|
|
<view>{{ item.name }}</view>
|
|
|
|
|
</label>
|
|
|
|
|
</radio-group>
|
|
|
|
|
</view>
|
2024-01-29 19:14:01 +08:00
|
|
|
|
|
2024-01-29 19:35:37 +08:00
|
|
|
|
<!-- http://localhost:9000/#/pages/index/i18n -->
|
2024-01-29 20:19:15 +08:00
|
|
|
|
<button @click="testI18n" class="mt-20 mb-44">测试弹窗</button>
|
2024-01-29 19:35:37 +08:00
|
|
|
|
</view>
|
2024-01-29 19:14:01 +08:00
|
|
|
|
</template>
|
2024-01-29 18:59:17 +08:00
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-05-04 10:59:10 +08:00
|
|
|
|
import i18n, { formatI18n, formatString, translate } from '@/locale/index'
|
2024-04-02 21:20:40 +08:00
|
|
|
|
import { testI18n } from '@/utils/i18n'
|
2024-01-29 18:59:17 +08:00
|
|
|
|
|
2024-01-29 19:56:25 +08:00
|
|
|
|
const current = ref(uni.getLocale())
|
2024-04-25 16:18:14 +08:00
|
|
|
|
const user = { name: '张三', detail: { height: 178, weight: '75kg' } }
|
2024-01-29 19:14:01 +08:00
|
|
|
|
const languages = [
|
|
|
|
|
{
|
2024-01-29 19:56:25 +08:00
|
|
|
|
value: 'zh-Hans',
|
2024-01-29 19:14:01 +08:00
|
|
|
|
name: '中文',
|
|
|
|
|
checked: 'true',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'en',
|
|
|
|
|
name: '英文',
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const radioChange = (evt) => {
|
|
|
|
|
// console.log(evt)
|
|
|
|
|
current.value = evt.detail.value
|
2024-01-29 19:56:25 +08:00
|
|
|
|
// 下面2句缺一不可!!!
|
2024-01-29 19:14:01 +08:00
|
|
|
|
uni.setLocale(evt.detail.value)
|
2024-01-29 19:56:25 +08:00
|
|
|
|
i18n.global.locale = evt.detail.value
|
2024-01-29 19:14:01 +08:00
|
|
|
|
}
|
2024-01-29 18:59:17 +08:00
|
|
|
|
</script>
|
2024-01-29 19:35:37 +08:00
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.uni-list {
|
|
|
|
|
position: relative;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
width: 100%;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
border-radius: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.radio-group {
|
|
|
|
|
width: 200px;
|
2024-01-29 20:19:15 +08:00
|
|
|
|
margin: 10px auto;
|
2024-01-29 19:35:37 +08:00
|
|
|
|
border-radius: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.uni-list-cell {
|
|
|
|
|
position: relative;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
background-color: #bcecd1;
|
|
|
|
|
}
|
|
|
|
|
</style>
|