Skip to content

Commit

Permalink
用ComboBox选择翻译引擎(GPT或谷歌生草机)
Browse files Browse the repository at this point in the history
  • Loading branch information
ks233 committed Oct 26, 2023
1 parent 7729431 commit 2ea2c28
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
52 changes: 27 additions & 25 deletions GUI/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions GUI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public string Sentence
{
sentence = value;
dictForm.UpdateTranslationPanelText(sentence);
UpdateMecabResult(RunMecab());
if (checkBoxAutoTranslate.Checked)
{
TranslateSentence();
_ = TranslateSentence();
}
UpdateMecabResult(RunMecab());

}
}

Expand Down Expand Up @@ -67,6 +68,7 @@ private async void MainForm_Load(object sender, EventArgs e)
dictForm.Show();
dictForm.Hide();
UpdateExtraPromptCombobox();
comboBoxTranslator.SelectedIndex = 0;
}

private void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
Expand Down Expand Up @@ -263,9 +265,17 @@ private void textBoxHwnd_TextChanged(object sender, EventArgs e)

async private Task TranslateSentence()
{
var chat = GptCaller.CreateTranslateConversation(sentence);
ClearTranslationText();
GptCaller.StreamResponse(chat, res => AppendTranslationText(res));
if (comboBoxTranslator.SelectedIndex == 0)
{
var chat = GptCaller.CreateTranslateConversation(sentence);
ClearTranslationText();
GptCaller.StreamResponse(chat, res => AppendTranslationText(res));
}
else if (comboBoxTranslator.SelectedIndex == 1)
{
// 这个接口效果真的好烂。。。用来翻译片假名还可以,翻译句子真就生草机
await webView.ExecuteScriptAsync($"runGoogleTrans(\"{sentence}\")");
}
}

async private void buttonTranslate_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -325,14 +335,7 @@ private void comboBoxExtraPrompts_Click(object sender, EventArgs e)

async private void checkBoxTranslateKatakana_CheckedChanged(object sender, EventArgs e)
{

await webView.ExecuteScriptAsync($"setTranslateKatakana({checkBoxTranslateKatakana.Checked.ToString().ToLower()})");
}

async private void buttonGoogleTrans_Click(object sender, EventArgs e)
{
// 这个接口效果真的好烂。。。用来翻译片假名还可以,翻译句子真就生草机
await webView.ExecuteScriptAsync($"runGoogleTrans(\"{sentence}\")");
}
}
}

0 comments on commit 2ea2c28

Please sign in to comment.