diff --git a/src/lib/constant.ts b/src/lib/constant.ts index 05f59d3..00b0411 100644 --- a/src/lib/constant.ts +++ b/src/lib/constant.ts @@ -10,13 +10,11 @@ export type Language = { export const languages: Language[] = [ { key: "zh", value: "Chinese" }, { key: "en", value: "English" }, - { key: "nl", value: "Dutch" }, + { key: "ja", value: "Japanese" }, + { key: "ru", value: "Russian" }, { key: "fr", value: "French" }, { key: "de", value: "Deutsch" }, { key: "it", value: "Italian" }, - { key: "ja", value: "Japanese" }, - { key: "pl", value: "Polish" }, - { key: "pt", value: "Portuguese" }, - { key: "ru", value: "Russian" }, { key: "es", value: "Spanish" }, + { key: "pt", value: "Portuguese" }, ]; diff --git a/src/pages/api/lib/baidu.ts b/src/pages/api/lib/baidu.ts index 43aaa46..a55a35d 100644 --- a/src/pages/api/lib/baidu.ts +++ b/src/pages/api/lib/baidu.ts @@ -4,6 +4,12 @@ import MD5 from "md5"; import axios from "axios"; import { getErrorMessage } from "@/pages/api/lib/utils"; +const languageMap: Record = { + "ja": "jp", + "fr": "fra", + "es": "spa", +}; + export class Baidu { public APPID: string; public APPKEY: string; @@ -13,6 +19,8 @@ export class Baidu { this.APPKEY = APPKEY; } async translate(text: string, target: string, source: string = "auto") { + target = languageMap[target] || target + source = languageMap[source] || source const salt = String(Math.random()).slice(2) const sign = MD5(this.APPID+text+salt+this.APPKEY) try { diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 217b7ed..d784e7a 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -37,12 +37,8 @@ export default function Home() { const [to, setTo] = useState("zh"); const [isExpanded, setIsExpanded] = useState(false); - const [loader, setLoader] = useState( - initializeTranslateloader, - ); - const [result, setResult] = useState( - initializeTranslateState, - ); + const [loader, setLoader] = useState(initializeTranslateloader); + const [result, setResult] = useState(initializeTranslateState); const handleClick = () => { setIsExpanded(!isExpanded);