108 lines
3.4 KiB
JavaScript
108 lines
3.4 KiB
JavaScript
const DEFAULT_LOCALE = "zh-CN";
|
|
|
|
const REGION_LABELS = {
|
|
americas: "美洲",
|
|
europe: "欧洲",
|
|
"middle-east-africa": "中东与非洲",
|
|
"asia-pacific": "亚太",
|
|
global: "全球",
|
|
};
|
|
|
|
const FEED_LABELS = {
|
|
"Global Monitor / World": "全球监测",
|
|
"Global Monitor / Americas": "美洲监测",
|
|
"Global Monitor / Europe": "欧洲监测",
|
|
"Global Monitor / MEA": "中东与非洲监测",
|
|
"Global Monitor / APAC": "亚太监测",
|
|
};
|
|
|
|
const LOCATION_SOURCE_LABELS = {
|
|
region_anchor: "区域锚点",
|
|
ai_inferred_target: "AI 推断位置",
|
|
headline_location_hint: "标题位置线索",
|
|
headline_country_hint: "标题国家线索",
|
|
};
|
|
|
|
const ENRICHMENT_STATUS_LABELS = {
|
|
pending: "待增强",
|
|
queued: "增强排队中",
|
|
attempted: "增强中",
|
|
success: "已汉化",
|
|
content_only: "已汉化",
|
|
location_only: "位置已增强",
|
|
unavailable: "AI 未配置",
|
|
provider_error: "增强失败",
|
|
parse_error: "增强解析失败",
|
|
no_result: "暂无增强结果",
|
|
};
|
|
|
|
const TITLE_PLACEHOLDERS = {
|
|
queued: "新闻汉化排队中",
|
|
attempted: "新闻汉化中",
|
|
provider_error: "新闻汉化失败,正在重试",
|
|
parse_error: "新闻解析失败,正在重试",
|
|
unavailable: "等待 AI 配置",
|
|
no_result: "新闻汉化待重试",
|
|
location_only: "新闻汉化待重试",
|
|
};
|
|
|
|
const SUMMARY_PLACEHOLDERS = {
|
|
queued: "中文概要正在生成,请稍后刷新。",
|
|
attempted: "中文概要正在生成,请稍后刷新。",
|
|
provider_error: "中文概要生成失败,系统会重新提交增强任务。",
|
|
parse_error: "中文概要解析失败,系统会重新提交增强任务。",
|
|
unavailable: "AI 服务配置完成后将生成中文概要。",
|
|
no_result: "中文概要暂未生成,系统会继续重试。",
|
|
location_only: "已完成位置增强,中文概要将继续重试。",
|
|
};
|
|
|
|
function normalizeText(value) {
|
|
return String(value ?? "").replace(/\s+/g, " ").trim();
|
|
}
|
|
|
|
function getLocalization(item, locale = DEFAULT_LOCALE) {
|
|
const localizations = item?.localizations;
|
|
const localized = localizations && typeof localizations === "object"
|
|
? localizations[locale]
|
|
: null;
|
|
return localized && typeof localized === "object" ? localized : {};
|
|
}
|
|
|
|
export function getNewsDisplayTitle(item, locale = DEFAULT_LOCALE) {
|
|
const localized = getLocalization(item, locale).title;
|
|
if (localized || item?.display_title) {
|
|
return normalizeText(item?.display_title || localized);
|
|
}
|
|
return normalizeText(
|
|
TITLE_PLACEHOLDERS[item?.enrichment_status]
|
|
|| "新闻汉化中",
|
|
);
|
|
}
|
|
|
|
export function getNewsDisplaySummary(item, locale = DEFAULT_LOCALE) {
|
|
const localized = getLocalization(item, locale).summary;
|
|
if (localized || item?.display_summary) {
|
|
return normalizeText(item?.display_summary || localized);
|
|
}
|
|
return normalizeText(
|
|
SUMMARY_PLACEHOLDERS[item?.enrichment_status]
|
|
|| "中文概要生成中,请稍后刷新。",
|
|
);
|
|
}
|
|
|
|
export function getNewsRegionLabel(region, fallback = "") {
|
|
return REGION_LABELS[region] || fallback || region || REGION_LABELS.global;
|
|
}
|
|
|
|
export function getNewsFeedLabel(feedName) {
|
|
return FEED_LABELS[feedName] || feedName || "聚合源";
|
|
}
|
|
|
|
export function getNewsLocationSourceLabel(source) {
|
|
return LOCATION_SOURCE_LABELS[source] || source || "位置来源";
|
|
}
|
|
|
|
export function getNewsEnrichmentStatusLabel(status) {
|
|
return ENRICHMENT_STATUS_LABELS[status] || status || "增强状态";
|
|
}
|