Skip to content

Commit

Permalink
Merge branch 'main' into online
Browse files Browse the repository at this point in the history
  • Loading branch information
SIPC committed Feb 24, 2024
2 parents 817dd33 + 0dab206 commit d5c7528
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
14 changes: 14 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/lib/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
];
5 changes: 3 additions & 2 deletions src/pages/api/lib/baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const languageMap: Record<string, string> = {
"ja": "jp",
"fr": "fra",
"es": "spa",
"ko": "kor",
};

export class Baidu {
Expand All @@ -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");
}
Expand Down
10 changes: 9 additions & 1 deletion src/pages/api/lib/chatgpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/pages/api/lib/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
},
Expand Down
10 changes: 9 additions & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ export default function Home() {
onChange={setFrom}
placeholder={`Source Language`}
/>
<ChevronRight className={`shrink-0 w-3 h-3 mx-2`} />
<ChevronRight className={`shrink-0 w-3 h-3 mx-2`}
onClick={() => {
const temp = from;
if (temp != 'auto') {
setFrom(to);
setTo(temp);
}
}}
/>
<LanguageSelect
value={to}
onChange={setTo}
Expand Down

0 comments on commit d5c7528

Please sign in to comment.