Code
HTTP
/** @jsxImportSource https://esm.sh/react */
import React, { useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function TranslationApp() {
const [sourceText, setSourceText] = useState("");
const [translatedText, setTranslatedText] = useState("");
const [errorMessage, setErrorMessage] = useState("");
const [sourceLanguage, setSourceLanguage] = useState("auto");
const [targetLanguage, setTargetLanguage] = useState("zh");
const languages = [
{ code: "auto", name: "自动检测" },
{ code: "zh", name: "中文" },
{ code: "en", name: "英语" },
{ code: "ja", name: "日语" },
{ code: "ko", name: "韩语" },
{ code: "fr", name: "法语" },
{ code: "de", name: "德语" },
{ code: "es", name: "西班牙语" },
{ code: "ru", name: "俄语" }
];
const handleTranslate = async () => {
// 重置之前的错误消息
setErrorMessage("");
setTranslatedText("");
// 检查输入是否为空
if (!sourceText.trim()) {
setErrorMessage("请输入要翻译的文本");
return;
}
try {
const response = await fetch("/translate", {
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
sky_porie_fire443-deepltranslatorapp.web.val.run
Updated: November 19, 2024