fix: map chinese language requests to zh-CN
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { getJSON } from "../../../api";
|
||||
import { langQuery, type Lang } from "../../../i18n";
|
||||
import { MOCK_POSTS } from "../../../mocks/mockPosts";
|
||||
import type { Post, PostListResponse, PostScope } from "../../../types/post";
|
||||
|
||||
@@ -12,7 +13,7 @@ export type PostStreamParams = {
|
||||
scope: PostScope;
|
||||
type?: string;
|
||||
language?: string;
|
||||
lang: string;
|
||||
lang: Lang;
|
||||
};
|
||||
|
||||
export type PostStreamResult = {
|
||||
@@ -65,7 +66,7 @@ function filterMock(params: PostStreamParams): Post[] {
|
||||
|
||||
function buildRealUrl(params: PostStreamParams, cursor?: string): string {
|
||||
const sp = new URLSearchParams();
|
||||
sp.set("lang", params.lang);
|
||||
sp.set("lang", langQuery(params.lang));
|
||||
sp.set("limit", String(PAGE_SIZE));
|
||||
if (params.scope.kind === "category") sp.set("category", params.scope.slug);
|
||||
if (params.type && params.type !== "all") sp.set("type", params.type);
|
||||
|
||||
@@ -383,5 +383,5 @@ export function useI18n() {
|
||||
}
|
||||
|
||||
export function langQuery(lang: Lang) {
|
||||
return lang;
|
||||
return lang === "zh" ? "zh-CN" : lang;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { getJSON, itemsOrEmpty, type Category } from "../api";
|
||||
import { MessageStream } from "../components/messageStream/MessageStream";
|
||||
import { useI18n } from "../i18n";
|
||||
import { langQuery, useI18n } from "../i18n";
|
||||
|
||||
export function CategoryPage() {
|
||||
const { slug = "" } = useParams();
|
||||
@@ -11,7 +11,9 @@ export function CategoryPage() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!slug) return;
|
||||
getJSON<Category[]>(`/api/categories?lang=${encodeURIComponent(lang)}`)
|
||||
getJSON<Category[]>(
|
||||
`/api/categories?lang=${encodeURIComponent(langQuery(lang))}`,
|
||||
)
|
||||
.then((cats) =>
|
||||
setTitle(itemsOrEmpty(cats).find((x) => x.slug === slug)?.name ?? slug),
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from "../components/LatestUpdateRow";
|
||||
import { RecommendedCard } from "../components/RecommendedCard";
|
||||
import { SectionHeader } from "../components/SectionHeader";
|
||||
import { useI18n } from "../i18n";
|
||||
import { langQuery, useI18n } from "../i18n";
|
||||
import { categoryCardLines } from "../utils/categoryDisplay";
|
||||
|
||||
export function Home() {
|
||||
@@ -23,7 +23,7 @@ export function Home() {
|
||||
const [canScrollRec, setCanScrollRec] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const q = `?lang=${encodeURIComponent(lang)}`;
|
||||
const q = `?lang=${encodeURIComponent(langQuery(lang))}`;
|
||||
Promise.all([
|
||||
getJSON<Category[]>(`/api/categories${q}`),
|
||||
getJSON<{ items: Resource[] }>(`/api/resources/recommended${q}&limit=12`),
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
postJSON,
|
||||
type Resource,
|
||||
} from "../api";
|
||||
import { useI18n } from "../i18n";
|
||||
import { langQuery, useI18n } from "../i18n";
|
||||
import { LANG_OPTIONS, languageLabel } from "../i18nLanguages";
|
||||
import { typeFilterLabel } from "../resourceTypeLabels";
|
||||
|
||||
@@ -80,7 +80,7 @@ export function SearchPage() {
|
||||
|
||||
const query = useMemo(() => {
|
||||
const p = new URLSearchParams();
|
||||
p.set("lang", lang);
|
||||
p.set("lang", langQuery(lang));
|
||||
p.set("limit", "50");
|
||||
if (q) p.set("q", q);
|
||||
if (type && type !== "all") p.set("type", type);
|
||||
|
||||
@@ -54,7 +54,7 @@ export function AdminResourceForm() {
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
getJSON<Category[]>("/api/categories?lang=zh")
|
||||
getJSON<Category[]>("/api/categories?lang=zh-CN")
|
||||
.then(setCats)
|
||||
.catch(() => setCats([]));
|
||||
}, []);
|
||||
|
||||
@@ -32,7 +32,7 @@ export function AdminResources() {
|
||||
const [total, setTotal] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
getJSON<Category[]>("/api/categories?lang=zh")
|
||||
getJSON<Category[]>("/api/categories?lang=zh-CN")
|
||||
.then((cats) => {
|
||||
const m: Record<number, string> = {};
|
||||
for (const c of cats) m[c.id] = c.name;
|
||||
|
||||
Reference in New Issue
Block a user