perf: update chinese and english automatic recognition proportion configuration item

main
DESKTOP-3BO4HSG\ksat 2 years ago
parent 4974e53bf1
commit a93c422838

@ -17,6 +17,7 @@ namespace STranslate.Model
{
return new ConfigModel
{
AutoScale = 0.8,
WordPickupInterval = 200,
IsBright = true,
SourceLanguage = LanguageEnum.AUTO.GetDescription(),
@ -44,7 +45,12 @@ namespace STranslate.Model
}
/// <summary>
/// 是否亮色模式
/// 自动识别语种标度
/// </summary>
[JsonProperty("autoScale")]
public double AutoScale { get; set; }
/// <summary>
/// 取词间隔
/// </summary>
[JsonProperty("wordPickupInterval")]
public double WordPickupInterval { get; set; }

@ -65,6 +65,21 @@
</CheckBox>
</WrapPanel>
</GroupBox>
<GroupBox Header="语种识别(zh-en)"
ToolTip="根据英文字符占所有字符比例判断中英文">
<WrapPanel Margin="0,5,0,5">
<Slider Value="{Binding DataContext.AutoScale, ElementName=window}"
Minimum="0.01"
Maximum="0.99"
MinWidth="200"
TickFrequency="0.01"
TickPlacement="None"
IsSnapToTickEnabled="True">
</Slider>
<TextBlock Text="{Binding AutoScale, StringFormat={}{0}}" Margin="10,0,0,0" />
</WrapPanel>
</GroupBox>
<GroupBox Header="取词间隔"
ToolTip="划词翻译实现原理是用户用鼠标划词后模拟Ctrl+C间隔一定时间后程序再从剪切板取词如果电脑反应慢可能会出现取不到词的问题将间隔调大可以适配一些老旧的机器">
<WrapPanel Margin="0,5,0,5">

@ -23,6 +23,10 @@ namespace STranslate.View
{
InitializeComponent();
#if DEBUG
this.window.Topmost = true;
#endif
DataContext = ViewModel.SettingsVM.Instance;
}
}

@ -231,6 +231,10 @@ namespace STranslate.ViewModel
{
_globalConfig = ConfigHelper.Instance.ReadConfig<ConfigModel>();
//读取自动识别语种比例
var scale = _globalConfig.AutoScale;
SettingsVM.Instance.AutoScale = (scale <= 0 || scale >= 1) ? 0.8 : scale;
//读取间隔
var tmp = _globalConfig.WordPickupInterval;
SettingsVM.Instance.WordPickupInterval = (tmp == 0 || tmp > 1000 || tmp < 100) ? 200 : tmp;
@ -271,6 +275,7 @@ namespace STranslate.ViewModel
{
ConfigHelper.Instance.WriteConfig(new ConfigModel
{
AutoScale = SettingsVM.Instance.AutoScale,
WordPickupInterval = SettingsVM.Instance.WordPickupInterval,
IsBright = Application.Current.Resources.MergedDictionaries[0].Source.ToString() == ThemeDefault ? true : false,
SourceLanguage = InputComboSelected,
@ -306,9 +311,8 @@ namespace STranslate.ViewModel
var ratio = (double)engStr.Length / text.Length;
//3. 判断英文字符个数占第一步所有字符个数比例,若超过一半则判定原字符串为英文字符串,否则为中文字符串
//TODO: 配置项
if (ratio > 0.8)
//3. 判断英文字符个数占第一步所有字符个数比例,若超过一定比例则判定原字符串为英文字符串,否则为中文字符串
if (ratio > SettingsVM.Instance.AutoScale)
{
return new Tuple<string, string>(LanguageEnum.EN.GetDescription(), LanguageEnum.ZH.GetDescription());
}

@ -124,6 +124,12 @@ namespace STranslate.ViewModel
private string _version;
public string Version { get => _version; set => UpdateProperty(ref _version, value); }
/// <summary>
/// 语种识别比例
/// </summary>
private double _autoScale;
public double AutoScale { get => _autoScale; set => UpdateProperty(ref _autoScale, value); }
/// <summary>
/// 取词间隔
/// </summary>

Loading…
Cancel
Save