Skip to content

Commit

Permalink
自定义文本不被翻译的长度限制,避免某些英语游戏长文本不翻译的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
hanmin0822 committed Jul 3, 2020
1 parent ae388f7 commit 3a93f93
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions MisakaTranslator-WPF/IAppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ string SecondTranslator
set;
}

[Option(Alias = "Translate_All.TransLimitNums", DefaultValue = 100)]
int TransLimitNums
{
get;
set;
}

[Option(Alias = "OCR_All.OCRsource", DefaultValue = "BaiduOCR")]
string OCRsource
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<StackPanel Margin="20,36,0,0">
<hc:ComboBox Name="FirstTransCombox" Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitleAlignment="Left" hc:InfoElement.Title="{StaticResource GeneralTransSettingsPage_FirstTranslator}" hc:Poptip.HitMode="None" hc:Poptip.IsOpen="{Binding IsMouseOver,RelativeSource={RelativeSource Self}}" hc:Poptip.Content="{StaticResource GeneralTransSettingsPage_TransSourceHint}" hc:Poptip.Placement="Top" SelectionChanged="FirstTransCombox_SelectionChanged" HorizontalAlignment="Left"/>
<hc:ComboBox Name="SecondTransCombox" Margin="0,10,0,0" Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitleAlignment="Left" hc:InfoElement.Title="{StaticResource GeneralTransSettingsPage_SecondTranslator}" hc:Poptip.HitMode="None" hc:Poptip.IsOpen="{Binding IsMouseOver,RelativeSource={RelativeSource Self}}" hc:Poptip.Content="{StaticResource GeneralTransSettingsPage_TransSourceHint}" hc:Poptip.Placement="Top" SelectionChanged="SecondTransCombox_SelectionChanged" HorizontalAlignment="Left"/>

<hc:NumericUpDown Name="TransLimitBox" Margin="0,10,0,0" Width="380" Style="{StaticResource NumericUpDownExtend}" hc:InfoElement.TitleAlignment="Left" hc:InfoElement.TitleWidth="140" hc:InfoElement.Title="{StaticResource GeneralTransSettingsPage_Translimit}" HorizontalAlignment="Left" ValueChanged="TransLimitBox_ValueChanged"/>

<CheckBox Name="EachRowTransCheckBox" Margin="0,10,0,0" Content="{StaticResource GeneralTransSettingsPage_EachRowTransCheckBox}" IsChecked="True" hc:InfoElement.Title="{StaticResource GeneralTransSettingsPage_SecondTranslator}" hc:Poptip.HitMode="None" hc:Poptip.IsOpen="{Binding IsMouseOver,RelativeSource={RelativeSource Self}}" hc:Poptip.Content="{StaticResource GeneralTransSettingsPage_EachRowTransHint}" hc:Poptip.Placement="Right" Click="EachRowTransCheckBox_Click" HorizontalAlignment="Left"/>
</StackPanel>
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public TranslatorGeneralSettingsPage()
SecondTransCombox.SelectedIndex = CommonFunction.GetTranslatorIndex(Common.appSettings.SecondTranslator);

EachRowTransCheckBox.IsChecked = Convert.ToBoolean(Common.appSettings.EachRowTrans);

TransLimitBox.Value = Common.appSettings.TransLimitNums;
}

private void FirstTransCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand All @@ -49,6 +51,11 @@ private void SecondTransCombox_SelectionChanged(object sender, SelectionChangedE
private void EachRowTransCheckBox_Click(object sender, RoutedEventArgs e)
{
Common.appSettings.EachRowTrans = Convert.ToString(EachRowTransCheckBox.IsChecked);
}
}

private void TransLimitBox_ValueChanged(object sender, HandyControl.Data.FunctionEventArgs<double> e)
{
Common.appSettings.TransLimitNums = (int)TransLimitBox.Value;
}
}
}
2 changes: 1 addition & 1 deletion MisakaTranslator-WPF/TransWinSettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<StackPanel>
<hc:ComboBox Name="firstFont" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitleAlignment="Top" hc:InfoElement.Title="{StaticResource TransWinSettingsWin_FontName}" Margin="10" />

<hc:NumericUpDown Name="firstFontSize" hc:InfoElement.Title="{StaticResource TransWinSettingsWin_FontSize}" Margin="10" Style="{StaticResource NumericUpDownExtend}"/>
<hc:NumericUpDown Name="firstFontSize" hc:InfoElement.Title="{StaticResource TransWinSettingsWin_FontSize}" Margin="10" Style="{StaticResource NumericUpDownExtend}" />

<TextBlock Text="{StaticResource TransWinSettingsWin_BgColor}" HorizontalAlignment="Center" Margin="15"/>
<Button Name="firstColorBtn" Content="{StaticResource TransWinSettingsWin_BtnChooseColor}" Margin="0" Width="200" Style="{StaticResource ButtonPrimary}" Click="ChooseColorBtn_Click"/>
Expand Down
4 changes: 2 additions & 2 deletions MisakaTranslator-WPF/TranslateWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ public void DataRecvEventHandler(object sender, SolvedDataRecvEventArgs e)
//去乱码
repairedText = repairedText.Replace("_", "").Replace("-", "").Replace("+", "").Replace("&", "");

//补充:如果去重之后的文本长度超过100,直接不翻译、不显示
if (repairedText.Length <= 100)
//补充:如果去重之后的文本长度超过指定值(默认100),直接不翻译、不显示
if (repairedText.Length <= Common.appSettings.TransLimitNums)
{
//2.5 清除面板
SourceTextPanel.Children.Clear();
Expand Down
2 changes: 2 additions & 0 deletions MisakaTranslator-WPF/lang/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,6 @@

<sys:String x:Key="TransWinSettingsWin_KanaCbox">开启日语原文假名标注</sys:String>
<sys:String x:Key="MainWindow_AutoUpdateCheck">发现新版本!点击确认进入下载页面,点击取消忽略本次更新提示。</sys:String>

<sys:String x:Key="GeneralTransSettingsPage_Translimit">翻译限制字数</sys:String>
</ResourceDictionary>
2 changes: 2 additions & 0 deletions MisakaTranslator-WPF/lang/zh-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,6 @@
<sys:String x:Key="TransWinSettingsWin_KanaCbox">开启日语原文假名标注</sys:String>

<sys:String x:Key="MainWindow_AutoUpdateCheck">发现新版本!点击确认进入下载页面,点击取消忽略本次更新提示。</sys:String>

<sys:String x:Key="GeneralTransSettingsPage_Translimit">翻译限制字数</sys:String>
</ResourceDictionary>

0 comments on commit 3a93f93

Please sign in to comment.