feat(front): enhance app configuration fetching and add localization support for "powered by" text

This commit is contained in:
keven
2025-10-19 13:33:55 +08:00
parent e6cc1b0229
commit d8c9491a99
4 changed files with 33 additions and 4 deletions

View File

@@ -1,6 +1,14 @@
const useMyAppConfig = () => {
const { data } = useFetch("/config");
return data;
};
const { data } = useFetch<{
data: {
site_title: Record<string, string>
site_desc: Record<string, string>
site_url: string
site_icon: string
site_bg_url: string
}
}>('/api/config')
return computed(() => data?.value?.data)
}
export default useMyAppConfig;
export default useMyAppConfig

View File

@@ -105,6 +105,7 @@
"copySuccess": "Copy Success"
},
"about": {
"powerBy": "Power by {0} as a open source temporary file sharing platform",
"file": "File",
"task": "Task",
"admin": "Admin",

View File

@@ -105,6 +105,7 @@
"copySuccess": "复制成功"
},
"about": {
"powerBy": "由 {0} 驱动的开源自托管临时文件分享平台",
"file": "文件",
"task": "任务",
"admin": "站长",

19
front/lib/renderI18n.ts Normal file
View File

@@ -0,0 +1,19 @@
import { useI18n } from 'vue-i18n'
const renderI18n = (json: Record<string, string>, defaultKey: string, locale?: string) => {
const { locale: _locale } = useI18n()
if (!json) return ''
if (!locale) {
locale = _locale.value
}
if (!json?.[locale]) {
const [baseLocaleKey, subLocaleKey] = locale?.split('-') || []
if (!baseLocaleKey || !subLocaleKey) {
return json?.[defaultKey]
}
return renderI18n(json, defaultKey, baseLocaleKey)
}
return json?.[locale]
}
export default renderI18n