diff --git a/README.md b/README.md index 4b50870..3bd6b0f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ WPF 开发的一款即用即走的翻译工具 - [x] 实现基本翻译功能 - [x] 优化防止多开 - [x] 添加划词翻译 +- [ ] 添加复制结果蛇形、大小驼峰 - [ ] 优化 DeepL 服务并打包成库引入进项目 - [ ] 添加 OCR 翻译 - [ ] 优化划词翻译(未选中则取消翻译) diff --git a/STranslate/MainWindow.xaml.cs b/STranslate/MainWindow.xaml.cs index 411b8c8..c31b877 100644 --- a/STranslate/MainWindow.xaml.cs +++ b/STranslate/MainWindow.xaml.cs @@ -60,8 +60,6 @@ namespace STranslate if (e.Key == Key.Escape) { this.Hide(); - vm.InputTxt = string.Empty; - vm.OutputTxt = string.Empty; //取消置顶 this.TopImg.Source = UnLockImgPath; @@ -144,6 +142,8 @@ namespace STranslate { vm.InputTxt = string.Empty; vm.OutputTxt = string.Empty; + vm.HumpRet = string.Empty; + vm.SnakeRet = string.Empty; } /// diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs index f08a193..8b24eac 100644 --- a/STranslate/ViewModel/MainVM.cs +++ b/STranslate/ViewModel/MainVM.cs @@ -32,10 +32,26 @@ namespace STranslate.ViewModel return string.IsNullOrEmpty(OutputTxt) ? false : true; }, (_) => { - System.Diagnostics.Debug.Print("手动复制翻译结果: " + OutputTxt); Clipboard.SetText(OutputTxt); }); + //复制蛇形结果 + CopySnakeResultCmd = new RelayCommand((_) => + { + return string.IsNullOrEmpty(SnakeRet) ? false : true; + }, (_) => + { + Clipboard.SetText(SnakeRet); + }); + //复制驼峰结果 + CopyHumpResultCmd = new RelayCommand((_) => + { + return string.IsNullOrEmpty(HumpRet) ? false : true; + }, (_) => + { + Clipboard.SetText(HumpRet); + }); + //翻译 TranslateCmd = new RelayCommand((_) => { return string.IsNullOrEmpty(InputTxt) ? false : true; @@ -65,12 +81,55 @@ namespace STranslate.ViewModel return; } OutputTxt = translateResp; + + var splitList = translateResp.Split(' ').ToList(); + if (splitList.Count > 1) + { + SnakeRet = GenSnakeString(splitList); + HumpRet = GenHumpString(splitList); + } + + System.Diagnostics.Debug.Print(SnakeRet); + System.Diagnostics.Debug.Print(HumpRet); } catch (Exception ex) { OutputTxt = ex.Message; } } + /// + /// 构造蛇形结果 + /// + /// + /// + private string GenSnakeString(List req) + { + //Alarm statistics + var ret = string.Empty; + + req.ForEach(x => + { + ret += "_" + x.ToLower(); + }); + return ret.Substring(1); + } + /// + /// 构造驼峰结果 + /// + /// + /// + private string GenHumpString(List req) + { + //TODO: I'm your father 出错情况 + var ret = string.Empty; + var arr = req.ToArray(); + ret += arr[0].Substring(0, 1).ToLower() + arr[0].Substring(1); + for (int i = 1; i < arr.Length; i++) + { + ret += arr[i].Substring(0, 1).ToUpper() + arr[0].Substring(1); + } + return ret; + } #endregion handle @@ -78,6 +137,11 @@ namespace STranslate.ViewModel public ICommand TranslateCmd { get; private set; } public ICommand CopyResultCmd { get; private set; } + public ICommand CopySnakeResultCmd { get; private set; } + public ICommand CopyHumpResultCmd { get; private set; } + + public string SnakeRet { get; set; } + public string HumpRet { get; set; } private string _InputTxt; public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); }