Files
Arkie-Library-Frontend/src/resourceTypeLabels.ts

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-05-16 00:18:22 +08:00
/** Labels for resource type filter chips (keys match API `type` + `all`). */
export function typeFilterLabel(
t: (key: string) => string,
tp: string,
): string {
if (tp === "all") return t("filterAll");
return resourceTypeLabel(t, tp);
}
/** Type label without the "all" filter branch (e.g. admin tables). */
export function resourceTypeDisplay(
t: (key: string) => string,
type: string,
): string {
const key = `type_${type}`;
const label = t(key);
return label !== key ? label : type;
}
/** Localized label for API resource `type` (image, video, link, …). */
export function resourceTypeLabel(
t: (key: string) => string,
type: string,
): string {
const key = `type_${type}`;
const label = t(key);
return label !== key ? label : type;
}
/** Localized label for resource language code (zh, en, ja, ko, vi, id, ms). */
2026-05-16 00:18:22 +08:00
export function resourceLanguageLabel(
t: (key: string) => string,
langCode: string,
): string {
const lc = langCode.trim().toLowerCase();
const normalized =
lc === "zh-cn" || lc === "zh-tw" || lc === "zh-hans" ? "zh" : lc;
const key = `lang_${normalized}`;
const label = t(key);
return label !== key ? label : langCode.trim();
2026-05-16 00:18:22 +08:00
}