From a93c422838620e8010c8cbfee9aed04aee81e93e Mon Sep 17 00:00:00 2001 From: "DESKTOP-3BO4HSG\\ksat" Date: Tue, 17 Jan 2023 10:45:03 +0800 Subject: [PATCH] perf: update chinese and english automatic recognition proportion configuration item --- STranslate/Model/ConfigModel.cs | 8 +++++++- STranslate/View/SettingsWindow.xaml | 15 +++++++++++++++ STranslate/View/SettingsWindow.xaml.cs | 4 ++++ STranslate/ViewModel/MainVM.cs | 10 +++++++--- STranslate/ViewModel/SettingsVM.cs | 6 ++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/STranslate/Model/ConfigModel.cs b/STranslate/Model/ConfigModel.cs index 4e109e0..3ca9d35 100644 --- a/STranslate/Model/ConfigModel.cs +++ b/STranslate/Model/ConfigModel.cs @@ -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 } /// - /// 是否亮色模式 + /// 自动识别语种标度 + /// + [JsonProperty("autoScale")] + public double AutoScale { get; set; } + /// + /// 取词间隔 /// [JsonProperty("wordPickupInterval")] public double WordPickupInterval { get; set; } diff --git a/STranslate/View/SettingsWindow.xaml b/STranslate/View/SettingsWindow.xaml index f3fdcdf..c49c1f7 100644 --- a/STranslate/View/SettingsWindow.xaml +++ b/STranslate/View/SettingsWindow.xaml @@ -65,6 +65,21 @@ + + + + + + + + diff --git a/STranslate/View/SettingsWindow.xaml.cs b/STranslate/View/SettingsWindow.xaml.cs index 404f505..0351a9d 100644 --- a/STranslate/View/SettingsWindow.xaml.cs +++ b/STranslate/View/SettingsWindow.xaml.cs @@ -23,6 +23,10 @@ namespace STranslate.View { InitializeComponent(); +#if DEBUG + this.window.Topmost = true; +#endif + DataContext = ViewModel.SettingsVM.Instance; } } diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs index 52ee0ec..735538b 100644 --- a/STranslate/ViewModel/MainVM.cs +++ b/STranslate/ViewModel/MainVM.cs @@ -231,6 +231,10 @@ namespace STranslate.ViewModel { _globalConfig = ConfigHelper.Instance.ReadConfig(); + //读取自动识别语种比例 + 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(LanguageEnum.EN.GetDescription(), LanguageEnum.ZH.GetDescription()); } diff --git a/STranslate/ViewModel/SettingsVM.cs b/STranslate/ViewModel/SettingsVM.cs index c23dcf7..4d7a44b 100644 --- a/STranslate/ViewModel/SettingsVM.cs +++ b/STranslate/ViewModel/SettingsVM.cs @@ -124,6 +124,12 @@ namespace STranslate.ViewModel private string _version; public string Version { get => _version; set => UpdateProperty(ref _version, value); } + /// + /// 语种识别比例 + /// + private double _autoScale; + public double AutoScale { get => _autoScale; set => UpdateProperty(ref _autoScale, value); } + /// /// 取词间隔 ///