From d8c9491a99455bfe100d931c94877655a4d82f74 Mon Sep 17 00:00:00 2001 From: keven Date: Sun, 19 Oct 2025 13:33:55 +0800 Subject: [PATCH] feat(front): enhance app configuration fetching and add localization support for "powered by" text --- front/composables/useMyAppConfig.ts | 16 ++++++++++++---- front/i18n/locales/en.json | 1 + front/i18n/locales/zh-CN.json | 1 + front/lib/renderI18n.ts | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 front/lib/renderI18n.ts diff --git a/front/composables/useMyAppConfig.ts b/front/composables/useMyAppConfig.ts index 5856f40..d062dd6 100644 --- a/front/composables/useMyAppConfig.ts +++ b/front/composables/useMyAppConfig.ts @@ -1,6 +1,14 @@ const useMyAppConfig = () => { - const { data } = useFetch("/config"); - return data; -}; + const { data } = useFetch<{ + data: { + site_title: Record + site_desc: Record + site_url: string + site_icon: string + site_bg_url: string + } + }>('/api/config') + return computed(() => data?.value?.data) +} -export default useMyAppConfig; +export default useMyAppConfig diff --git a/front/i18n/locales/en.json b/front/i18n/locales/en.json index 1358da5..c46a299 100644 --- a/front/i18n/locales/en.json +++ b/front/i18n/locales/en.json @@ -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", diff --git a/front/i18n/locales/zh-CN.json b/front/i18n/locales/zh-CN.json index a7007ec..2c50cbb 100644 --- a/front/i18n/locales/zh-CN.json +++ b/front/i18n/locales/zh-CN.json @@ -105,6 +105,7 @@ "copySuccess": "复制成功" }, "about": { + "powerBy": "由 {0} 驱动的开源自托管临时文件分享平台", "file": "文件", "task": "任务", "admin": "站长", diff --git a/front/lib/renderI18n.ts b/front/lib/renderI18n.ts new file mode 100644 index 0000000..ab6c943 --- /dev/null +++ b/front/lib/renderI18n.ts @@ -0,0 +1,19 @@ +import { useI18n } from 'vue-i18n' + +const renderI18n = (json: Record, 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