fix: map chinese language requests to zh-CN
This commit is contained in:
@@ -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