Skip to content

Commit c2b4e67

Browse files
committed
refactor: move page titles to i18n files
1 parent ba28c3c commit c2b4e67

File tree

12 files changed

+74
-33
lines changed

12 files changed

+74
-33
lines changed

app/components/AppHeader.vue

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,38 @@ function onBack() {
1313
1414
const { t } = useI18n()
1515
16+
/**
17+
* Get page title
18+
* Located in i18n/locales/json
19+
*/
1620
const title = computed(() => {
17-
if (!route.meta)
18-
return ''
19-
return route.meta.i18n_key ? t(route.meta.i18n_key) : (route.meta.title || '')
21+
if (route.name) {
22+
return t(`navbar.${route.name}`)
23+
}
24+
25+
return t('navbar.Undefined')
2026
})
2127
22-
const showLeftArrow = computed(() => route.name && routeWhiteList.includes(route.name))
28+
/**
29+
* Display the left arrow
30+
* If route name is in route white list, display left arrow
31+
*/
32+
const showLeftArrow = computed(() => {
33+
if (route.name && routeWhiteList.includes(route.name)) {
34+
return true
35+
}
36+
37+
return false
38+
})
2339
</script>
2440

2541
<template>
26-
<VanNavBar
42+
<van-nav-bar
2743
:title="title"
44+
clickable
45+
placeholder
46+
fixed
2847
:left-arrow="!showLeftArrow"
29-
clickable placeholder fixed
3048
@click-left="onBack"
3149
/>
3250
</template>

app/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import type { RouteRecordName } from 'vue-router'
33
/**
44
* Use the AppFooter routing whitelist
55
*/
6-
export const useAppFooterRouteNames: RouteRecordName[] = ['index', 'profile']
6+
export const useAppFooterRouteNames: RouteRecordName[] = ['Home', 'Profile']

app/pages/counter/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import useCounter from '~/composables/counter'
33
44
definePageMeta({
5-
title: '🍍 持久化 Pinia 状态',
6-
i18n_key: 'menu.persistPiniaState',
5+
name: 'Counter',
76
})
87
98
const counter = useCounter()

app/pages/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { Locale } from 'vant'
66
77
definePageMeta({
88
layout: 'default',
9-
title: '主页',
10-
i18n_key: 'menu.home',
9+
name: 'Home',
1110
})
1211
1312
const color = useColorMode()

app/pages/keepalive/index.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ defineOptions({
66
definePageMeta({
77
name: 'Keepalive',
88
keepalive: true,
9-
title: '🧡 KeepAlive',
10-
i18n_key: 'menu.keepAlive',
119
})
1210
1311
const value = ref(1)

app/pages/profile/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<script setup lang="ts">
22
definePageMeta({
33
layout: 'default',
4-
title: '我的',
5-
i18n_key: 'menu.profile',
4+
name: 'Profile',
65
})
76
</script>
87

app/pages/prose/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { useProseStore } from '~/stores/prose'
33
44
definePageMeta({
55
layout: 'default',
6-
title: '随笔',
7-
i18n_key: 'menu.fetch',
6+
name: 'Prose',
87
})
98
109
const proseStore = useProseStore()

app/pages/unocss/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
22
definePageMeta({
3-
title: '🎨 Unocss 示例',
4-
i18n_key: 'menu.unocssExample',
3+
name: 'Unocss',
54
})
65
</script>
76

app/types/vue-router.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ declare module 'vue-router' {
22
interface RouteMeta {
33
/** page title */
44
title?: string
5-
/** i18n key */
6-
i18n_key?: string
75
}
86
}
97

i18n/locales/en-US.json

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
{
2-
"menu": {
2+
"navbar": {
3+
"Home": "Home",
4+
"Counter": "Persist Pinia State",
5+
"Profile": "Profile",
6+
"Prose": "Network Request",
7+
"Unocss": "Unocss Example",
8+
"Keepalive": "KeepAlive Demo",
9+
"Undefined": "Undefined title"
10+
},
11+
12+
"tabbar": {
313
"home": "Home",
4-
"profile": "Profile",
14+
"profile": "Profile"
15+
},
16+
17+
"menu": {
518
"darkMode": "🌗 Dark Mode",
619
"language": "📚 Language",
720
"404Demo": "🙅 Page 404 Demo",
@@ -10,30 +23,32 @@
1023
"persistPiniaState": "💾 Persist Pinia State",
1124
"fetch": "🏄 Network Request"
1225
},
13-
"tabbar": {
14-
"home": "Home",
15-
"profile": "Profile"
16-
},
26+
1727
"unocss_page": {
1828
"hello": "Hello {0}",
1929
"desc": "This is a simple example of Unocss in action.",
2030
"btn_txt": "Button"
2131
},
32+
2233
"error_page": {
2334
"back_btn": "Back",
2435
"txt": "Not found"
2536
},
37+
2638
"profile_page": {
2739
"txt": "WIP"
2840
},
41+
2942
"keepalive_page": {
3043
"label": "The current component will be cached"
3144
},
45+
3246
"counter_page": {
3347
"label": "This is a simple example of persisting Pinia state. To verify its effectiveness, you can refresh the interface and observe it.",
3448
"label_num": "Number",
3549
"btn_add": "Add"
3650
},
51+
3752
"prose_page": {
3853
"btn_fetch": "Fetch",
3954
"btn_clear": "Clear",

0 commit comments

Comments
 (0)