feat: 把i18n的东西放到 i18n.vue

This commit is contained in:
菲鸽 2024-01-29 18:59:17 +08:00
parent 7e2cda4886
commit 960580fd62
3 changed files with 14 additions and 12 deletions

View File

@ -29,6 +29,10 @@ const i18n = createI18n({
* @param { string } localeKey keyeg: "app.name"
*/
export const translate = (localeKey: string) => {
if (!localeKey) {
console.error(`[i18n] Function translate(), localeKey param is required`)
return ''
}
const locale = getLocale()
const message = messages[locale]
if (Object.keys(message).includes(localeKey)) {

View File

@ -1,5 +1,3 @@
<template>{{ $t('app.name') }}</template>
<route lang="json">
{
"style": {
@ -7,3 +5,11 @@
}
}
</route>
<template>{{ $t('app.name') }}</template>
<script lang="ts" setup>
import { testI18n } from '@/utils/index'
testI18n()
</script>

View File

@ -2,8 +2,8 @@
<route lang="json5" type="home">
{
style: {
// "navigationStyle": "custom",
navigationBarTitleText: '%app.name%',
navigationStyle: 'custom',
navigationBarTitleText: '首页',
},
}
</route>
@ -12,7 +12,6 @@
class="bg-white h-full overflow-hidden pt-2 px-4"
:style="{ marginTop: safeAreaInsets?.top + 'px' }"
>
<view>{{ $t('app.name') }}</view>
<view class="mt-12">
<image src="/static/logo.svg" alt="" class="w-40 h-40 block mx-auto" />
</view>
@ -38,15 +37,8 @@
</template>
<script lang="ts" setup>
import { testI18n } from '@/utils/index'
testI18n()
//
const { safeAreaInsets } = uni.getSystemInfoSync()
const author = ref('菲鸽')
console.log(author)
</script>
<style>