Skip to content

Commit f505503

Browse files
object-kazmaslow
andauthored
feat: i18n support for document title (#148)
* docs: update docs; * fix: error on opening app-console * Update Crowdin configuration file * feat: i18n support for document title * chore: update language * Update Crowdin configuration file Co-authored-by: maslow <[email protected]>
1 parent c55e660 commit f505503

File tree

13 files changed

+4201
-10
lines changed

13 files changed

+4201
-10
lines changed

crowdin.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
files:
2+
- source: /packages/web/locales/en.yml
3+
translation: /packages/web/locales/%locale%.yml

packages/web/.env.development

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# just a flag
22
ENV = 'development'
33

4+
45
PORT = 9527
56

67
VITE_APP_CONSOLE_URI = 'http://localhost:9528/app-console'
8+

packages/web/.env.production

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# just a flag
22
ENV = 'production'
33

4+
45
VITE_APP_CONSOLE_URI = '/app-console'
6+

packages/web/auto-imports.d.ts

-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ declare global {
110110
const useAttrs: typeof import('vue')['useAttrs']
111111
const useBase64: typeof import('@vueuse/core')['useBase64']
112112
const useBattery: typeof import('@vueuse/core')['useBattery']
113-
const useBluetooth: typeof import('@vueuse/core')['useBluetooth']
114113
const useBreakpoints: typeof import('@vueuse/core')['useBreakpoints']
115114
const useBroadcastChannel: typeof import('@vueuse/core')['useBroadcastChannel']
116115
const useBrowserLocation: typeof import('@vueuse/core')['useBrowserLocation']
@@ -158,7 +157,6 @@ declare global {
158157
const useGeolocation: typeof import('@vueuse/core')['useGeolocation']
159158
const useI18n: typeof import('vue-i18n')['useI18n']
160159
const useIdle: typeof import('@vueuse/core')['useIdle']
161-
const useImage: typeof import('@vueuse/core')['useImage']
162160
const useInfiniteScroll: typeof import('@vueuse/core')['useInfiniteScroll']
163161
const useIntersectionObserver: typeof import('@vueuse/core')['useIntersectionObserver']
164162
const useInterval: typeof import('@vueuse/core')['useInterval']

packages/web/locales/en.yml

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
app:
2+
title: Laf Cloud
13
layout:
24
topbar:
35
title: Laf Cloud
@@ -17,3 +19,14 @@ utils:
1719
email: Email is invalid
1820
password: '{name} requires at least 8 digits'
1921
required: '{name} cannot be empty'
22+
message:
23+
confirm:
24+
buttons:
25+
cancel: Cancel
26+
confirm: confirm
27+
default-message: Are you sure you want to do this?
28+
default-title: hint
29+
error:
30+
default-message: operation failed
31+
success:
32+
default-message: Successful operation

packages/web/locales/zh-CN.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
app:
2+
title: Laf 云开发
13
layout:
24
topbar:
35
title: Laf 云开发
@@ -10,7 +12,7 @@ pages:
1012
account: 账户
1113
login-btn: 登录
1214
password: 密码
13-
title: Laf 云开发账户登录
15+
title: 登录
1416
register: 注册
1517
utils:
1618
form:

packages/web/router.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import 'vue-router'
2+
3+
declare module 'vue-router' {
4+
interface RouteMeta {
5+
title?: string
6+
}
7+
}

packages/web/src/App.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
2-
import { initLanguageModule } from './modules/locales'
2+
import { initLocaleModule } from './modules/locales'
33
4-
initLanguageModule()
4+
initLocaleModule()
55
</script>
66

77
<template>

packages/web/src/modules/locales.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,34 @@ const commonLanguages = intersection(userLocales, supportLanguageNames)
3535
export const bestDefaultLanguage = commonLanguages.length > 0 ? commonLanguages[0] : 'en'
3636

3737
export function initLanguageModule() {
38-
// 同步语言设置
38+
// sync config from config to i18n
3939
const { locale } = useI18n()
4040
const config = useConfigStore()
4141
watchEffect(() => {
4242
locale.value = config.local.language
4343
})
4444
}
45+
46+
export function initDocTitleModule() {
47+
const { t, locale } = useI18n()
48+
const title = useTitle()
49+
const route = useRoute()
50+
watch([() => route.meta.title, locale], () => {
51+
const titleParts = [t('app.title')]
52+
53+
if (route.meta.title) {
54+
// support of expressions like t(\'xxxx.xxxx\')
55+
const matchResult = /t\(['\"`](([\w\d.]+))['\"`]\)/g.exec(route.meta.title)
56+
titleParts.unshift(matchResult ? t(matchResult[1]) : route.meta.title)
57+
}
58+
59+
title.value = titleParts.join(' - ')
60+
}, {
61+
immediate: true,
62+
})
63+
}
64+
65+
export function initLocaleModule() {
66+
initLanguageModule()
67+
initDocTitleModule()
68+
}

packages/web/src/pages/account/login.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ const login = async (loginEl: FormInstance | undefined) => {
8585
<route lang="yaml">
8686
name: login
8787
meta:
88-
title: 登录
88+
title: t('pages.account.login.title')
8989
</route>

packages/web/src/router/permission.ts

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ router.beforeEach(async (to, from, next) => {
1212
// start progress bar
1313
NProgress.start()
1414

15-
// set page title
16-
document.title = to.meta.title ? `${to.meta.title} - LAF 云开发` : 'LAF 云开发'
17-
1815
// determine whether the user has logged in
1916
const hasToken = getToken()
2017
if (hasToken) {

packages/web/vite.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export default defineConfig({
9494
},
9595
'/sys-extension-api': {
9696
target: 'http://console.127-0-0-1.nip.io:8080/',
97+
9798
changeOrigin: true,
9899
},
99100
},
@@ -104,4 +105,5 @@ export default defineConfig({
104105
external: [],
105106
},
106107
},
108+
107109
})

0 commit comments

Comments
 (0)