feat(admin): 内容管理支持多语言和标签

This commit is contained in:
Zhou Weidong committed 2026-10-24 17:30:52 +08:00
1 parent eaee765239
commit 2b2c6bd708
14 files changed
+1080 -458

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
// Author: fruit.com.cn
export interface ContentLanguage {
code: string
label: string
}
export const CONTENT_LANGUAGES: ContentLanguage[] = [
{ code: 'zh', label: '中文' },
{ code: 'en', label: '英文' },
{ code: 'id', label: '印尼语' }
]
export function languageLabel(code: string) {
return CONTENT_LANGUAGES.find((item) => item.code === code)?.label || code
}
export function languageCodes(locales?: Record<string, string> | null) {
const source = locales || {}
return CONTENT_LANGUAGES.map((item) => item.code).filter((code) => source[code])
}
export function localesFromColumns(
locales: Record<string, string> | null | undefined,
zh?: string,
en?: string,
id?: string
) {
if (locales && Object.keys(locales).length) {
return { ...locales }
}
const result: Record<string, string> = {}
if (zh) result.zh = zh
if (en) result.en = en
if (id) result.id = id
if (!result.zh) result.zh = ''
return result
}
export function payloadLocales(locales: Record<string, string>, codes: string[]) {
const result: Record<string, string> = {}
codes.forEach((code) => {
result[code] = String(locales[code] || '').trim()
})
return result
}