From ca3d75a4fc2e0c81c56bbad1df9079784826cfe8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-3BO4HSG\\ksat" Date: Tue, 10 Jan 2023 13:41:18 +0800 Subject: [PATCH] chore: update tray and readme --- README.md | 35 ++++++++++++++++++++++++++- STranslate/Properties/AssemblyInfo.cs | 4 +-- STranslate/View/MainWindow.xaml | 13 +++++++--- STranslate/ViewModel/MainVM.cs | 10 ++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f894b79..86521ab 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ - [x] 添加亮/暗主题 - [x] 添加 UI 设置缓存(用户目录下 `AppData\Local\STranslate`) - [x] 添加语音合成 -- [ ] 添加 OCR 翻译 +- [x] 添加离线截图翻译 - [ ] 添加翻译记录缓存功能 ## 使用 @@ -47,6 +47,7 @@ 1. 全局监听快捷键 - `Alt` + `A` 打开软件界面,输入内容按回车翻译 - `Alt` + `D` 复制当前鼠标选中内容并翻译 +- `Alt` + `S` 截图选中区域内容并翻译 - `Alt` + `G` 打开窗口(不清空内容) 2. 软件内快捷键 @@ -60,6 +61,38 @@ ![previews](./example_tray.png) +4. 0.15 添加离线 OCR 功能,其使用 [tesseract](https://github.com/tesseract-ocr/tesseract) 目前仅支持英文 + +
+ 自修改提示 + +有经验者可自行下载 [语言包](https://github.com/tesseract-ocr/tessdata) 至 `tessdata` 目录后修改 `Util`中`TesseractGetText`方法即可 + +```C# +public static string TesseractGetText(Bitmap bmp) +{ + try + { + using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) + //using (var engine = new TesseractEngine(@"./tessdata", "chi_sim", EngineMode.Default)) + { + using(var pix = PixConverter.ToPix(bmp)) + { + using (var page = engine.Process(pix)) + { + return page.GetText(); + } + } + } + } + catch (Exception ex) + { + throw ex; + } +} +``` +
+ ## 接口失效 若远端接口均失效,需要自己本地运行翻译服务(感谢[zu1k](https://github.com/zu1k)),根据自己的系统 [下载可执行文件](https://github.com/zu1k/removed-2022-07-12/releases/tag/0.1.2) 自己的版本,软件右上角选择 `local` 接口即可 diff --git a/STranslate/Properties/AssemblyInfo.cs b/STranslate/Properties/AssemblyInfo.cs index c3abdd3..5793438 100644 --- a/STranslate/Properties/AssemblyInfo.cs +++ b/STranslate/Properties/AssemblyInfo.cs @@ -47,6 +47,6 @@ using System.Windows; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.4.0")] -[assembly: AssemblyFileVersion("0.1.4.0")] +[assembly: AssemblyVersion("0.1.5.0")] +[assembly: AssemblyFileVersion("0.1.5.0")] [assembly: Guid("CE252DD8-179F-4544-9989-453F5DEA378D")] \ No newline at end of file diff --git a/STranslate/View/MainWindow.xaml b/STranslate/View/MainWindow.xaml index 49ffaad..7e44596 100644 --- a/STranslate/View/MainWindow.xaml +++ b/STranslate/View/MainWindow.xaml @@ -23,11 +23,16 @@ - + - + - + diff --git a/STranslate/ViewModel/MainVM.cs b/STranslate/ViewModel/MainVM.cs index d9b351c..bfd2ca7 100644 --- a/STranslate/ViewModel/MainVM.cs +++ b/STranslate/ViewModel/MainVM.cs @@ -16,13 +16,17 @@ namespace STranslate.ViewModel { public MainVM() { + #region Initial if (!ReadConfig()) { ExitApp(-1); } + TrayToolTip = $"{System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)} " + + $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}"; InputCombo = LanguageEnumDict.Keys.ToList(); OutputCombo = LanguageEnumDict.Keys.ToList(); + #endregion #region 托盘程序 //运行前检查是否开机自启 @@ -434,6 +438,12 @@ namespace STranslate.ViewModel public ICommand EscCmd { get; private set; } public ICommand SelectLangChangedCmd { get; private set; } + /// + /// 托盘程序ToolTip + /// + private string _TrayToolTip; + public string TrayToolTip { get => _TrayToolTip; set => UpdateProperty(ref _TrayToolTip, value); } + /// /// 是否开机自启 ///