添加 阿拉伯语 和 俄语

This commit is contained in:
2026-08-24 10:31:15 +08:00
parent e09f0eccda
commit 398bd6fac6
85 changed files with 2015 additions and 391 deletions
@@ -51,6 +51,8 @@ export default defineEventHandler(async (event) => {
today: await countBy('SELECT COUNT(*) AS c FROM assessment_submissions WHERE created_at >= ?', `${today} 00:00:00`),
zh: await countBy("SELECT COUNT(*) AS c FROM assessment_submissions WHERE lang = 'zh'"),
en: await countBy("SELECT COUNT(*) AS c FROM assessment_submissions WHERE lang = 'en'"),
ar: await countBy("SELECT COUNT(*) AS c FROM assessment_submissions WHERE lang = 'ar'"),
ru: await countBy("SELECT COUNT(*) AS c FROM assessment_submissions WHERE lang = 'ru'"),
}
const partnerStats = {
@@ -59,6 +61,8 @@ export default defineEventHandler(async (event) => {
today: await countBy('SELECT COUNT(*) AS c FROM partner_submissions WHERE created_at >= ?', `${today} 00:00:00`),
zh: await countBy("SELECT COUNT(*) AS c FROM partner_submissions WHERE lang = 'zh'"),
en: await countBy("SELECT COUNT(*) AS c FROM partner_submissions WHERE lang = 'en'"),
ar: await countBy("SELECT COUNT(*) AS c FROM partner_submissions WHERE lang = 'ar'"),
ru: await countBy("SELECT COUNT(*) AS c FROM partner_submissions WHERE lang = 'ru'"),
}
const recentAssessments = (
@@ -36,7 +36,7 @@ export default defineEventHandler(async (event) => {
let sql = 'SELECT * FROM assessment_submissions WHERE 1=1'
const params: unknown[] = []
if (lang === 'zh' || lang === 'en') {
if (lang === 'zh' || lang === 'en' || lang === 'ar' || lang === 'ru') {
sql += ' AND lang = ?'
params.push(lang)
}
@@ -37,7 +37,7 @@ export default defineEventHandler(async (event) => {
let sql = 'SELECT * FROM partner_submissions WHERE 1=1'
const params: unknown[] = []
if (lang === 'zh' || lang === 'en') {
if (lang === 'zh' || lang === 'en' || lang === 'ar' || lang === 'ru') {
sql += ' AND lang = ?'
params.push(lang)
}
+3 -2
View File
@@ -9,6 +9,7 @@ import {
type NewsArticleInput,
} from '~/server/utils/news'
import { fail, ok, pageOk } from '~/server/utils/response'
import { isSiteLocale } from '~/types/locale'
function authOrFail(event: Parameters<typeof requireAuth>[0]) {
const auth = requireAuth(event)
@@ -24,7 +25,7 @@ function parseMediaType(value: unknown): MediaType | null {
}
function parseInput(body: Partial<NewsArticleInput>): NewsArticleInput | null {
const locale = body.locale === 'zh' ? 'zh' : body.locale === 'en' ? 'en' : null
const locale = isSiteLocale(String(body.locale || '')) ? body.locale! : null
const mediaType = parseMediaType(body.mediaType)
const title = body.title?.trim()
const summary = body.summary?.trim()
@@ -84,7 +85,7 @@ export default defineEventHandler(async (event) => {
const { list, total } = await listNewsArticles({
page,
pageSize,
locale: localeRaw === 'en' || localeRaw === 'zh' ? localeRaw : undefined,
locale: isSiteLocale(localeRaw) ? localeRaw : undefined,
mediaType: parseMediaType(mediaTypeRaw) || undefined,
keyword: keyword || undefined,
status: statusRaw === 'published' || statusRaw === 'draft' ? statusRaw : undefined,
+2 -1
View File
@@ -1,6 +1,7 @@
import { requireAuth } from '~/server/utils/auth'
import { listPageSeo } from '~/server/utils/page-seo'
import { fail, ok } from '~/server/utils/response'
import { isSiteLocale } from '~/types/locale'
export default defineEventHandler(async (event) => {
const auth = requireAuth(event)
@@ -14,7 +15,7 @@ export default defineEventHandler(async (event) => {
const keyword = String(queryParams.keyword || '')
const list = await listPageSeo({
locale: locale === 'en' || locale === 'zh' ? locale : undefined,
locale: isSiteLocale(locale) ? locale : undefined,
keyword: keyword || undefined,
})
+2 -1
View File
@@ -2,6 +2,7 @@ import { nowStr } from '~/server/utils/auth'
import { execute } from '~/server/utils/mysql'
import { notifyAssessmentSubmission } from '~/server/utils/form-notification'
import { fail, ok } from '~/server/utils/response'
import { isSiteLocale } from '~/types/locale'
export default defineEventHandler(async (event) => {
const body = await readBody<{
@@ -14,7 +15,7 @@ export default defineEventHandler(async (event) => {
message?: string
}>(event)
const lang = body.lang === 'zh' ? 'zh' : 'en'
const lang = isSiteLocale(body.lang || '') ? body.lang : 'en'
const firstName = body.firstName?.trim()
const email = body.email?.trim()
const condition = body.condition?.trim()
+2 -1
View File
@@ -2,6 +2,7 @@ import { nowStr } from '~/server/utils/auth'
import { execute } from '~/server/utils/mysql'
import { notifyPartnerSubmission } from '~/server/utils/form-notification'
import { fail, ok } from '~/server/utils/response'
import { isSiteLocale } from '~/types/locale'
export default defineEventHandler(async (event) => {
const body = await readBody<{
@@ -15,7 +16,7 @@ export default defineEventHandler(async (event) => {
collaborate?: string
}>(event)
const lang = body.lang === 'zh' ? 'zh' : 'en'
const lang = isSiteLocale(body.lang || '') ? body.lang : 'en'
const firstName = body.firstName?.trim()
const lastName = body.lastName?.trim()
const companyName = body.companyName?.trim()
+59 -3
View File
@@ -1,11 +1,67 @@
import { listPublishedMedia } from '~/server/utils/news'
import { ok } from '~/server/utils/response'
import {
newsItems as seedNewsEn,
seedVideosEn,
type MediaPublicItem
} from '~/data/news-content'
import { newsItemsZh, seedVideosZh } from '~/data/locale/zh/news.zh'
import { isSiteLocale, type SiteLocale } from '~/types/locale'
function seedPublishedMedia(locale: SiteLocale) {
const useZh = locale === 'zh'
const articles = (useZh ? newsItemsZh : seedNewsEn).map(
(item): MediaPublicItem => ({
mediaType: 'article',
title: item.title,
summary: item.summary,
thumbnail: item.thumbnail,
thumbnailAlt: item.thumbnailAlt,
url: item.url
})
)
const videos = (useZh ? seedVideosZh : seedVideosEn).map(
(item): MediaPublicItem => ({
mediaType: 'video',
title: item.title,
summary: item.summary,
thumbnail: item.thumbnail,
thumbnailAlt: item.thumbnailAlt,
youtubeUrl: item.youtubeUrl,
tiktokUrl: item.tiktokUrl
})
)
const items = [...articles, ...videos]
return {
items,
articles: articles.map((item) => ({
title: item.title,
summary: item.summary,
thumbnail: item.thumbnail,
thumbnailAlt: item.thumbnailAlt,
url: item.url || ''
})),
videos: videos.map((item) => ({
title: item.title,
summary: item.summary,
thumbnail: item.thumbnail,
thumbnailAlt: item.thumbnailAlt,
youtubeUrl: item.youtubeUrl,
tiktokUrl: item.tiktokUrl
}))
}
}
export default defineEventHandler(async (event) => {
const query = getQuery(event)
const localeRaw = String(query.locale || 'en').trim()
const locale = localeRaw === 'zh' ? 'zh' : 'en'
const locale: SiteLocale = isSiteLocale(localeRaw) ? localeRaw : 'en'
const media = await listPublishedMedia(locale)
return ok(media)
try {
const media = await listPublishedMedia(locale)
return ok(media)
} catch (error) {
console.warn('[api/news] database unavailable, using seed media:', error)
return ok(seedPublishedMedia(locale))
}
})
+9 -7
View File
@@ -1,5 +1,6 @@
import { getPageSeoByRoute } from '~/server/utils/page-seo'
import { fail, ok } from '~/server/utils/response'
import { isSiteLocale } from '~/types/locale'
export default defineEventHandler(async (event) => {
const query = getQuery(event)
@@ -11,13 +12,14 @@ export default defineEventHandler(async (event) => {
return fail('缺少 routeKey 参数', 400)
}
const locale = localeRaw === 'zh' ? 'zh' : 'en'
const record = await getPageSeoByRoute(routeKey, locale)
const locale = isSiteLocale(localeRaw) ? localeRaw : 'en'
if (!record) {
setResponseStatus(event, 404)
return fail('未找到 SEO 配置', 404)
try {
const record = await getPageSeoByRoute(routeKey, locale)
// 无库配置时返回空数据,页面使用本地 SEO 文案,避免 404 触发致命错误导致白屏
return ok(record)
} catch (error) {
console.warn('[api/seo] database unavailable, falling back to page SEO:', error)
return ok(null)
}
return ok(record)
})