feat: align frontend languages with posts api

This commit is contained in:
TerryM
2026-05-26 07:36:53 +08:00
parent 453abfcec7
commit e7a5952d58
19 changed files with 565 additions and 544 deletions

View File

@@ -8,26 +8,21 @@ import {
type Resource,
} from "../api";
import { useI18n } from "../i18n";
import { LANG_OPTIONS, languageLabel } from "../i18nLanguages";
import { typeFilterLabel } from "../resourceTypeLabels";
const types = [
"all",
"image",
"video",
"music",
"ppt",
"pdf",
"text",
"link",
"archive",
] as const;
const resourceLangCodes = ["", "zh-TW", "zh-CN", "en"] as const;
function resourceLangLabel(t: (k: string) => string, code: string) {
if (!code) return t("filterLanguageAll");
if (code === "zh-TW") return t("lang_zh_TW");
if (code === "zh-CN") return t("lang_zh_CN");
return t("lang_en");
}
const resourceLangCodes = ["", ...LANG_OPTIONS.map((x) => x.code)] as const;
function ResultRow({ r }: { r: Resource }) {
const target = r.externalUrl || (r.fileUrl ? assetUrl(r.fileUrl) : null);
@@ -152,7 +147,7 @@ export function SearchPage() {
: "border-ark-line text-neutral-300"
}`}
>
{resourceLangLabel(t, code)}
{languageLabel(t, code)}
</button>
))}
</div>

View File

@@ -17,6 +17,7 @@ import { useAdminRouterMode } from "../../adminRouterMode";
const types = [
"image",
"video",
"music",
"ppt",
"pdf",
"text",
@@ -36,7 +37,7 @@ export function AdminResourceForm() {
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
const [rtype, setRtype] = useState<string>("image");
const [language, setLanguage] = useState("zh-TW");
const [language, setLanguage] = useState("zh");
const [categoryId, setCategoryId] = useState(1);
const [coverImage, setCoverImage] = useState("");
const [fileUrl, setFileUrl] = useState("");
@@ -53,7 +54,7 @@ export function AdminResourceForm() {
const [err, setErr] = useState<string | null>(null);
useEffect(() => {
getJSON<Category[]>("/api/categories?lang=zh-TW")
getJSON<Category[]>("/api/categories?lang=zh")
.then(setCats)
.catch(() => setCats([]));
}, []);
@@ -65,7 +66,7 @@ export function AdminResourceForm() {
setTitle(r.title || "");
setDescription(r.description || "");
setRtype(r.type || "image");
setLanguage(r.language || "zh-TW");
setLanguage(r.language || "zh");
setCategoryId(r.categoryId || 1);
setCoverImage(r.coverImage || "");
setFileUrl(r.fileUrl || "");
@@ -182,9 +183,13 @@ export function AdminResourceForm() {
value={language}
onChange={(e) => setLanguage(e.target.value)}
>
<option value="zh-TW">{t("lang_zh_TW")}</option>
<option value="zh-CN">{t("lang_zh_CN")}</option>
<option value="zh">{t("lang_zh")}</option>
<option value="en">{t("lang_en")}</option>
<option value="ja">{t("lang_ja")}</option>
<option value="ko">{t("lang_ko")}</option>
<option value="vi">{t("lang_vi")}</option>
<option value="id">{t("lang_id")}</option>
<option value="ms">{t("lang_ms")}</option>
</select>
</Field>
<Field label={t("status")}>

View File

@@ -32,7 +32,7 @@ export function AdminResources() {
const [total, setTotal] = useState(0);
useEffect(() => {
getJSON<Category[]>("/api/categories?lang=zh-TW")
getJSON<Category[]>("/api/categories?lang=zh")
.then((cats) => {
const m: Record<number, string> = {};
for (const c of cats) m[c.id] = c.name;