import Stack from "@mui/material/Stack"; import TextField from "@mui/material/TextField"; import Button from "@mui/material/Button"; import LoadingButton from "@mui/lab/LoadingButton"; import { OPT_TRANS_ALL, OPT_TRANS_MICROSOFT, OPT_TRANS_DEEPL, OPT_TRANS_DEEPLX, OPT_TRANS_DEEPLFREE, OPT_TRANS_BAIDU, OPT_TRANS_TENCENT, OPT_TRANS_OPENAI, OPT_TRANS_OPENAI_2, OPT_TRANS_OPENAI_3, OPT_TRANS_GEMINI, OPT_TRANS_CLOUDFLAREAI, OPT_TRANS_CUSTOMIZE, OPT_TRANS_NIUTRANS, URL_KISS_PROXY, URL_NIUTRANS_REG, DEFAULT_FETCH_LIMIT, DEFAULT_FETCH_INTERVAL, } from "../../config"; import { useState } from "react"; import { useI18n } from "../../hooks/I18n"; import Typography from "@mui/material/Typography"; import Accordion from "@mui/material/Accordion"; import AccordionSummary from "@mui/material/AccordionSummary"; import AccordionDetails from "@mui/material/AccordionDetails"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import Alert from "@mui/material/Alert"; import { useAlert } from "../../hooks/Alert"; import { useApi } from "../../hooks/Api"; import { apiTranslate } from "../../apis"; import Box from "@mui/material/Box"; import Link from "@mui/material/Link"; import { limitNumber } from "../../libs/utils"; function TestButton({ translator, api }) { const i18n = useI18n(); const alert = useAlert(); const [loading, setLoading] = useState(false); const handleApiTest = async () => { try { setLoading(true); const [text] = await apiTranslate({ translator, text: "hello world", fromLang: "en", toLang: "zh-CN", apiSetting: api, useCache: false, }); if (!text) { throw new Error("empty reault"); } alert.success(i18n("test_success")); } catch (err) { // alert.error(`${i18n("test_failed")}: ${err.message}`); let msg = err.message; try { msg = JSON.stringify(JSON.parse(err.message), null, 2); } catch (err) { // skip } alert.error( <>
{msg}
)}
>
);
} finally {
setLoading(false);
}
};
return (
{i18n("custom_api_help")}
)}