Skip to content

Commit c5ae4f8

Browse files
committed
feat: add i18n for app metadata
1 parent b4b5463 commit c5ae4f8

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

src/App.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<script setup lang="ts">
2+
import { useI18n } from 'vue-i18n'
23
import { useRouteCacheStore } from '@/stores'
34
5+
const { t } = useI18n()
6+
47
useHead({
5-
title: 'Vue3 Vant Mobile',
8+
title: () => t('app.name'),
69
meta: [
710
{
811
name: 'description',
9-
content: 'An mobile web apps template based on the Vue 3 ecosystem',
12+
content: () => t('app.description'),
1013
},
1114
{
1215
name: 'theme-color',
13-
content: () => isDark.value ? '#00aba9' : '#ffffff',
16+
content: () => isDark.value ? '#0B0A0A' : '#ffffff',
1417
},
1518
],
1619
link: [

src/constants/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
export const appName = 'vue3-vant-mobile'
2-
export const appDescription = 'An mobile web apps template based on the Vue 3 ecosystem'
1+
import { i18n } from '@/utils/i18n'
2+
3+
export const appName = () => i18n.global.t('app.name')
4+
export const appDescription = () => i18n.global.t('app.description')

src/locales/en-US.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"app": {
3+
"name": "Vue3 Vant Mobile",
4+
"description": "An mobile web apps template based on the Vue 3 ecosystem"
5+
},
6+
27
"navbar": {
38
"Home": "Home",
49
"Profile": "Profile",

src/locales/zh-CN.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"app": {
3+
"name": "Vue3 移动端模板",
4+
"description": "一个基于 Vue 3 生态系统的移动 web 应用模板"
5+
},
6+
27
"navbar": {
38
"Home": "主页",
49
"Profile": "我的",

src/router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ router.beforeEach(async (to: EnhancedRouteLocation) => {
3131
routeCacheStore.addRoute(to)
3232

3333
// Set page title
34-
setPageTitle(to.meta.title)
34+
setPageTitle(to.name)
3535

3636
if (isLogin() && !userStore.userInfo?.uid)
3737
await userStore.info()

src/utils/set-page-title.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { appName } from '@/constants'
2+
import { i18n } from '@/utils/i18n'
23

3-
export default function setPageTitle(title?: string): void {
4-
window.document.title = title ? `${title} - ${appName}` : appName
4+
export default function setPageTitle(name?: string): void {
5+
window.document.title = name ? `${i18n.global.t(`navbar.${name}`)} - ${appName()}` : appName()
56
}

0 commit comments

Comments
 (0)