From 8510b50cd06e53388beaed19e9187392884a1d24 Mon Sep 17 00:00:00 2001 From: "DESKTOP-3BO4HSG\\ksat" Date: Sat, 24 Dec 2022 09:28:02 +0800 Subject: [PATCH] feat: add multiple replication methods --- README.md | 18 +++--- STranslate/Images/copy.png | Bin 2293 -> 0 bytes STranslate/Images/copy_h.png | Bin 0 -> 2283 bytes STranslate/Images/copy_h2.png | Bin 0 -> 2256 bytes STranslate/Images/copy_s.png | Bin 0 -> 2372 bytes STranslate/MainWindow.xaml | 40 +++++-------- STranslate/MainWindow.xaml.cs | 37 ++++++++---- STranslate/Properties/Resources.Designer.cs | 24 +++++++- STranslate/Properties/Resources.resx | 12 +++- STranslate/STranslate.csproj | 12 +++- STranslate/STranslate.yml | 6 +- STranslate/ViewModel/MainVM.cs | 62 ++++++++++++++------ 12 files changed, 136 insertions(+), 75 deletions(-) delete mode 100644 STranslate/Images/copy.png create mode 100644 STranslate/Images/copy_h.png create mode 100644 STranslate/Images/copy_h2.png create mode 100644 STranslate/Images/copy_s.png diff --git a/README.md b/README.md index 3bd6b0f..ed679fc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -WPF 开发的一款即用即走的翻译工具 +WPF 开发的一款即开即用、即用即走的翻译工具 ## 功能 @@ -8,8 +8,9 @@ WPF 开发的一款即用即走的翻译工具 - [x] 实现基本翻译功能 - [x] 优化防止多开 - [x] 添加划词翻译 -- [ ] 添加复制结果蛇形、大小驼峰 -- [ ] 优化 DeepL 服务并打包成库引入进项目 +- [x] 添加复制结果蛇形、大小驼峰 +- [x] 优化 DeepL 服务并打包成库引入进项目 +> 自己构造的接口测试下来还是不够稳定,本来也是启发于 [ZU1k](https://github.com/zu1k) 就先用他开发的接口吧 - [ ] 添加 OCR 翻译 - [ ] 优化划词翻译(未选中则取消翻译) - [ ] 添加软件缓存功能 @@ -22,11 +23,9 @@ WPF 开发的一款即用即走的翻译工具 ## 使用 -首先在软件运行目录的 `STranslate.yml` 中添加自己的配置,这里推荐百度通用翻译 API 免费版 [申请教程(参照Bob WIKI)](https://bobtranslate.com/service/translate/baidu.html) - 打开软件后会静默在后台,等待调用 -1. 全局监听快捷键(日后升级成自定义) -- `Alt` + `A` 打开软件主界面,输入需要翻译的内容,选择目标语言,如果识别语种不正确则手动指定即可,翻译结束后选择复制或点击一键复制即可 +1. 全局监听快捷键 +- `Alt` + `A` 打开软件界面,输入内容按回车翻译 - `Alt` + `D` 复制当前鼠标选中内容并翻译 2. 软件内快捷键 @@ -39,5 +38,6 @@ WPF 开发的一款即用即走的翻译工具 ## 参考项目 监听全局快捷键功能参考如下项目,在此表示感谢 - -- [https://github.com/NPCDW/WpfTool](https://github.com/NPCDW/WpfTool) \ No newline at end of file +- [https://github.com/NPCDW/WpfTool](https://github.com/NPCDW/WpfTool) +翻译接口使用项目 [ZU1K](https://github.com/zu1k/removed-2022-07-12/releases/tag/0.1.2) +- [https://github.com/zu1k/removed-2022-07-12/releases/tag/0.1.2](https://github.com/zu1k/removed-2022-07-12/releases/tag/0.1.2) \ No newline at end of file diff --git a/STranslate/Images/copy.png b/STranslate/Images/copy.png deleted file mode 100644 index 9e3a2b35940376da25b05d3e2f3f0d152be28d95..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2293 zcmdT`|3B0F7k_OtGG8O2d?c06%3Up^e90R5ny=+MH@162z7-+M7H`(gT)KUADKQeF zv~J}4e5cY)iA)nCF>9Y;clk1gyFQ=KAMpA0^TYY_cs$QJk8{rBJkB|pp6-q+sBI_! zfQqw|-AS2*zSAao8SliCUdse5{-mQVc+#iG2VfJ^+0MqB94svGpzmJLdeO>kB7NA? zwEKoNy=Qm2;8&;fp4z8(QZmyBwyIG?c0pl{~=H`P_Xk~b40XXBb~;&ot9dgEhaWlC$MUqR){!uC8b*3v3#X)Wbp z;cVfOvF+8AFw4;wdpk6`Yh6EXrVFaJvQwZ@- z=G#O_b$1{8SApzyGDc6Oki*P44u7{OO$Eyrs_dEmBIWfn7CK`|lz~hFEYl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d}E6Un^|Co*$x-9SONYB`5X!En^n=?8Eu zDd_cj9mR`+f}D3wBq9lD;^=@D)M$l%90F5E`7b3Pi)K|(0zYsWK4g6g_OOZ8u@VIc zb2v!NXrV$Zktkx{@DToLwDucPtCzURx3H5Nh};DH(YoF;2^H(x**|`IRt4ph4Wm2K zcen&*(PdcqI~gXwluMhS_Dv}{m(;SG=?xMQn`$my_ToIB9;fr@|neZvd=3S7S&0`V-d zK?{*%%M%Z1^_noQS!*^LjsElEB_#+KuC4l9HM&bIdEuJRr><9_rtZBB8Ch;l{A5}~ z`s+Sj5Co#R$VNQAB%;7MSslfd{V~AV-reqrEiwIXat<-F diff --git a/STranslate/Images/copy_h.png b/STranslate/Images/copy_h.png new file mode 100644 index 0000000000000000000000000000000000000000..4938c344937142ccb2e02f0b3d2d3543d8ab36cb GIT binary patch literal 2283 zcmbVOe@xU?954O=K>?>|6g8_Aji|l;xZXhvx0~D{;5*syG zpYN~t`bJ)ER%}dS41yrBIoZy9ct?$ENF@B%Dk|>5TXZ0Mv4$W+M;ccIvSsTS1c@w> z3JUc?*Bp*l{3akMZqZcc4?r}6q}$5^fL|%jW`6-qFXJGAU(^9w=J&}OS7yV4yc`@G(*%YFA^J)iHq$VO7P|6K zhoXw8)kNYvNm|hq)+7Ko;N9*SC{5B7K{5oz;3UbJS&m`Q&<}&=RKdgLJ7QHuzQWm$rx37Wr55E1Fk% z0(JQHV+LSsU9PZ=ezo}hVH293SpwY%1*BiJR!|-giF{F0idA0BEP*m78QugqhbjVH zQ418s*ORHd9?2+8n;3Me3-FR`IFa0EiRc8nXv1LMXq=*PnkgVtISa{=%yc*)$!@4i z5hPD}zfcQjCLe>ssu6$={u3h&=$eM@FY%|c^)_O48U1H znsJIGS%x>8fyWAZ*ygGd>`CD3%W9|+Afv~^kgQ01@KloV;EcetIGZW}+zhNK?i8AG zr?S8({9eliVwpY%l#8ks>ZlA*6dL)YJ^>73a)BSl$=f%8!Fhwkm?z*$!f2vy65z->&(8;zN>o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U=^$1tLwG-DVTc zP(}~VkYoYw7L61x2p)z9EW?UsdUU;2;v2Lg(AJMMgdp*dW6V63r74nTc${R6ByIwX z2?uWY$S|adrC2v5Pz9rG%Vi(zN#GyPs#zsKM%L(|&G{Y^ZZdh?I73qc?sl_04g?SH zHVO<+xp}Sd$CRC7vswXKL|KV;)Dqy0j{LrH0gPZOK>)_7e0%^S^BRdZPr#Lg)`&2g%z}q#SymXI`fv#mrYARvh&)m9&W3iwO}WA{)7$y(Al@e z@Tx!Yr%WX2PHk6zs=sE_DJC@SwSf<^=MLo=i!MKbo*| zx{7Rlmp_ON&+nU)@yGo1tOUp5nkh#H^?mZQTgnzt`f%9>v*W#-$#)8oi}@!_fy?UV zyo8kWbNce{)}2o}nVNB=9$_wp_YLj(8F8&aoPh)FM-x73`@N07R;~AcwQ+d(@24}a zhu5Niru7+ro0K}QSGRig>X$n^JI{sv!G(>BKWo$H&ONQ`Vzc^gFYNLBFt6*=oIPy( z*)#EJ^yZFJ?`(g;=*n!*bXC4_q9=6-HyVfTT-dj2AnQ;?xWI+#kSFxp29BOxcSif> Nu$5L?4=i!D{{s=L`6vJY literal 0 HcmV?d00001 diff --git a/STranslate/Images/copy_s.png b/STranslate/Images/copy_s.png new file mode 100644 index 0000000000000000000000000000000000000000..b834f50c7050db859941fcf1e61ccf9d257a5e66 GIT binary patch literal 2372 zcmbVO3s4kg9ACs&q9)lxe6_6PEB5xm-ob623U?<*a)f{hX^wll-yIv=?Qy%u-SH^Q zvJ6J;>8Ocm1HIIk>0v-Tk>QCi5jn75y+-DCm_i1VlgLI z$+f1lyyVnyf@A|4ztauT2r_4$-_7v_KtXN5A-W7$S3@I)ih==KqP3D%w-MxvmJ$!h zF3HH@OA2_sfX$nW&hfL5zzGx%^*ak)GV3>BL0%S))oB7lgAk>_fF-L2(OhdLYLq+x z)oDnaCrKTesMiRbjpJ>$c$6k-iXa(+VsMgV6Z9;@prIcI&3Obnn`K%MG6tUvSiYjT zS%UESd>UVZM)EiaO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- - - - - + @@ -186,14 +181,9 @@ + + diff --git a/STranslate/MainWindow.xaml.cs b/STranslate/MainWindow.xaml.cs index 78fcdcf..fe3a4df 100644 --- a/STranslate/MainWindow.xaml.cs +++ b/STranslate/MainWindow.xaml.cs @@ -42,6 +42,8 @@ namespace STranslate notifyIcon.Icon = new System.Drawing.Icon(System.Windows.Application.GetResourceStream(new Uri("Images/translate.ico", UriKind.Relative)).Stream); notifyIcon.Visible = true; + notifyIcon.MouseDoubleClick += NotifyIcon_MouseDoubleClick; + System.Windows.Forms.MenuItem CrossWordTranslateMenuItemBTN = new System.Windows.Forms.MenuItem("划词翻译"); CrossWordTranslateMenuItemBTN.Click += new EventHandler(CrossWordTranslateMenuItem_Click); @@ -68,17 +70,6 @@ namespace STranslate } - /// - /// 显示主窗口 - /// - /// - /// - private void OpenMainWin_Click(object sender, EventArgs e) - { - this.Show(); - this.Activate(); - } - /// /// 移动 /// @@ -182,10 +173,32 @@ namespace STranslate { vm.InputTxt = string.Empty; vm.OutputTxt = string.Empty; - vm.HumpRet = string.Empty; + vm.SmallHumpRet = string.Empty; vm.SnakeRet = string.Empty; } + /// + /// 显示主窗口 + /// + /// + /// + private void OpenMainWin_Click(object sender, EventArgs e) + { + this.Show(); + this.Activate(); + } + + + /// + /// 左键双击 + /// + /// + /// + private void NotifyIcon_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e) + { + OpenMainWin_Click(null, null); + } + /// /// 输入翻译 /// diff --git a/STranslate/Properties/Resources.Designer.cs b/STranslate/Properties/Resources.Designer.cs index 984f0aa..c691968 100644 --- a/STranslate/Properties/Resources.Designer.cs +++ b/STranslate/Properties/Resources.Designer.cs @@ -63,9 +63,29 @@ namespace STranslate.Properties { /// /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// - internal static System.Drawing.Bitmap copy { + internal static System.Drawing.Bitmap copy_h { get { - object obj = ResourceManager.GetObject("copy", resourceCulture); + object obj = ResourceManager.GetObject("copy_h", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap copy_h2 { + get { + object obj = ResourceManager.GetObject("copy_h2", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap copy_s { + get { + object obj = ResourceManager.GetObject("copy_s", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } diff --git a/STranslate/Properties/Resources.resx b/STranslate/Properties/Resources.resx index 3ae3893..fdc2bb6 100644 --- a/STranslate/Properties/Resources.resx +++ b/STranslate/Properties/Resources.resx @@ -118,12 +118,18 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\images\copy.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\images\copy2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\images\copy_h.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\images\copy_h2.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\images\copy_s.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\images\crossword.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/STranslate/STranslate.csproj b/STranslate/STranslate.csproj index 7178ec4..7a42658 100644 --- a/STranslate/STranslate.csproj +++ b/STranslate/STranslate.csproj @@ -134,9 +134,6 @@ SettingsSingleFileGenerator Settings.Designer.cs - - PreserveNewest - PreserveNewest @@ -161,6 +158,15 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/STranslate/STranslate.yml b/STranslate/STranslate.yml index 8818743..b36eebd 100644 --- a/STranslate/STranslate.yml +++ b/STranslate/STranslate.yml @@ -1,6 +1,6 @@ -service: baidu +service: deepl baidu: - appid: 20220608001242348 - secretKey: nN2CGpQCbTodUnKDW04k + appid: + secretKey: deepl: url: http://127.0.0.1:8000/translate \ No newline at end of file diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs index 7263020..9f663f9 100644 --- a/STranslate/ViewModel/MainVM.cs +++ b/STranslate/ViewModel/MainVM.cs @@ -61,13 +61,21 @@ namespace STranslate.ViewModel { Clipboard.SetText(SnakeRet); }); - //复制驼峰结果 - CopyHumpResultCmd = new RelayCommand((_) => + //复制小驼峰结果 + CopySmallHumpResultCmd = new RelayCommand((_) => { - return string.IsNullOrEmpty(HumpRet) ? false : true; + return string.IsNullOrEmpty(SmallHumpRet) ? false : true; }, (_) => { - Clipboard.SetText(HumpRet); + Clipboard.SetText(SmallHumpRet); + }); + //复制大驼峰结果 + CopyLargeHumpResultCmd = new RelayCommand((_) => + { + return string.IsNullOrEmpty(LargeHumpRet) ? false : true; + }, (_) => + { + Clipboard.SetText(LargeHumpRet); }); //翻译 @@ -104,8 +112,9 @@ namespace STranslate.ViewModel var splitList = OutputTxt.Split(' ').ToList(); if (splitList.Count > 1) { - //SnakeRet = GenSnakeString(splitList); - //HumpRet = GenHumpString(splitList); + SnakeRet = GenSnakeString(splitList); + SmallHumpRet = GenHumpString(splitList, true); //小驼峰 + LargeHumpRet = GenHumpString(splitList, false); //大驼峰 } } catch (Exception ex) @@ -129,23 +138,30 @@ namespace STranslate.ViewModel }); return ret.Substring(1); } + /// /// 构造驼峰结果 /// /// + /// 是否为小驼峰 /// - private string GenHumpString(List req) + private string GenHumpString(List req, bool isSmallHump) { - //TODO: I'm your father 出错情况 - //TODO: 构造出错 - 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++) + string ret = string.Empty; + var array = req.ToArray(); + for (var j = 0; j < array.Length; j++) { - ret += arr[i].Substring(0, 1).ToUpper() + arr[0].Substring(1); + char[] chars = array[j].ToCharArray(); + if (j == 0 && isSmallHump) chars[0] = char.ToLower(chars[0]); + chars[0] = char.ToUpper(chars[0]); + for (int i = 1; i < chars.Length; i++) + { + chars[i] = char.ToLower(chars[i]); + } + ret += new string(chars); } return ret; + } #endregion handle @@ -156,12 +172,24 @@ namespace STranslate.ViewModel public ICommand CopyInputCmd { get; private set; } public ICommand CopyResultCmd { get; private set; } public ICommand CopySnakeResultCmd { get; private set; } - public ICommand CopyHumpResultCmd { get; private set; } + public ICommand CopySmallHumpResultCmd { get; private set; } + public ICommand CopyLargeHumpResultCmd { get; private set; } + /// + /// 构造蛇形结果 + /// private string _SnakeRet; public string SnakeRet { get => _SnakeRet; set => UpdateProperty(ref _SnakeRet, value); } - private string _HumpRet; - public string HumpRet { get => _HumpRet; set => UpdateProperty(ref _HumpRet, value); } + /// + /// 构造驼峰结果 + /// + private string _SmallHumpRet; + public string SmallHumpRet { get => _SmallHumpRet; set => UpdateProperty(ref _SmallHumpRet, value); } + /// + /// 构造驼峰结果 + /// + private string _LargeHumpRet; + public string LargeHumpRet { get => _LargeHumpRet; set => UpdateProperty(ref _LargeHumpRet, value); } private string _InputTxt; public string InputTxt { get => _InputTxt; set => UpdateProperty(ref _InputTxt, value); }