diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..c8da001 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,14 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +polar: # Replace with a single Polar username +custom: https://afdian.net/a/Lyrify diff --git a/src/lib/constant.ts b/src/lib/constant.ts index 00b0411..7d6e6fc 100644 --- a/src/lib/constant.ts +++ b/src/lib/constant.ts @@ -16,5 +16,6 @@ export const languages: Language[] = [ { key: "de", value: "Deutsch" }, { key: "it", value: "Italian" }, { key: "es", value: "Spanish" }, + { key: "ko", value: "Korean" }, { key: "pt", value: "Portuguese" }, ]; diff --git a/src/pages/api/lib/baidu.ts b/src/pages/api/lib/baidu.ts index a55a35d..48d591d 100644 --- a/src/pages/api/lib/baidu.ts +++ b/src/pages/api/lib/baidu.ts @@ -8,6 +8,7 @@ const languageMap: Record = { "ja": "jp", "fr": "fra", "es": "spa", + "ko": "kor", }; export class Baidu { @@ -24,10 +25,10 @@ export class Baidu { const salt = String(Math.random()).slice(2) const sign = MD5(this.APPID+text+salt+this.APPKEY) try { - const apiUrl =`http://api.fanyi.baidu.com/api/trans/vip/translate?q=${text}&from=${source}&to=${target}&appid=${this.APPID}&salt=${salt}&sign=${sign}`; + const apiUrl =`http://api.fanyi.baidu.com/api/trans/vip/translate?q=${encodeURIComponent(text)}&from=${source}&to=${target}&appid=${this.APPID}&salt=${salt}&sign=${sign}`; const response = await axios.get(apiUrl); if (response.data) { - return response.data.trans_result[0].dst; + return response.data.trans_result.map((item: { dst: any; }) => item.dst).join("\n\n"); } else { throw new Error("Invalid response from Baidu"); } diff --git a/src/pages/api/lib/chatgpt.ts b/src/pages/api/lib/chatgpt.ts index c1a2f65..de6a835 100644 --- a/src/pages/api/lib/chatgpt.ts +++ b/src/pages/api/lib/chatgpt.ts @@ -38,9 +38,17 @@ export class ChatGPT { const data = JSON.stringify({ model: this.model, messages: [ + { + role: "system", + content: `You are a professional, authentic translation engine, only returns translations.`, + }, + { + role: "user", + content: `Please translate the text from ${source} to ${target} language, without explaining my original text.`, + }, { role: "user", - content: `请将以下文本从${source}翻译为${target}:“${text}”(要求:输出的结果只能出现翻译结果,需要准确且清晰,不得出现翻译结果以外的内容,输出结果不可以带任何特殊的文本样式,'',""不得出现)`, + content: text, }, ], temperature: 0.4, diff --git a/src/pages/api/lib/gemini.ts b/src/pages/api/lib/gemini.ts index 6b07d59..03b5bff 100644 --- a/src/pages/api/lib/gemini.ts +++ b/src/pages/api/lib/gemini.ts @@ -37,7 +37,13 @@ export class Gemini { { parts: [ { - text: `请将以下文本从${source}翻译为${target}:“${text}”(要求:输出的结果只能出现翻译结果,需要准确且清晰,不得出现翻译结果以外的内容,输出结果不可以带任何特殊的文本样式,'',""不得出现)`, + text: `You are a professional, authentic translation engine, only returns translations.`, + }, + { + text: `Please translate the text from ${source} to ${target} language, without explaining my original text.`, + }, + { + text: text, }, ], }, diff --git a/src/pages/index.tsx b/src/pages/index.tsx index bf8f187..9e46646 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -166,7 +166,15 @@ export default function Home() { onChange={setFrom} placeholder={`Source Language`} /> - + { + const temp = from; + if (temp != 'auto') { + setFrom(to); + setTo(temp); + } + }} + />