tisfeng/Easydict

🐞 反馈问题:特定应用中无法使用划词翻译

Jerry23011 opened this issue · 74 comments

请先确认以下事项:

  • 已仔细阅读了 README
  • issues 页面搜索过问题(包括已关闭的 issue),但未能找到解决方法
  • Easydict 已升级到最新版本

问题描述

在 Pages、Keynote、Numbers、Word、微信、无边记、图书几个应用中无法正常使用划词翻译功能

重现步骤

  1. 启动上述应用,例如 Pages 或 Microsoft Word
  2. 选中文本
  3. 使用快捷键划词翻译
  4. 看到文本框中没有内容

期望结果

可以在上述应用中正常使用划词翻译

解决方案(可选)

在 Easydict/Easydict/Feature/EventMonitor/EZEventMonitor.m 文件中手动添加应用,模拟 ⌘C

设备信息 && 操作系统版本(可选)

macOS 13.3.1 (a)

奇怪,我试了一下 Pages,发现它居然原生就支持 Auxiliary 取词,不需要额外适配。 我的系统是 13.2

image

Word 确实不行,和这个一样 #81 (comment) ,我加一下。

试了一下,Pages 还是不好用
不知道是不是版本问题:Pages 版本 13.0 (7036.0.126)

还是不能取词吗?这就难搞,我也是这个版本 😢

你可以用 dev 分支断点调试一下,看看 Pages 这个取词错误 error 的值吗

- (BOOL)checkIfNeedUseShortcut:(NSString *)text error:(AXError)error {

项目不知道为什么,build 不起来,我回头再看看

build 的时候报错,想问一下这里是什么情况
截屏2023-05-05 09 36 57
截屏2023-05-05 09 37 43

像是桥接文件出了问题,你有改过代码文件吗?看一下 Easydict-Bridging-Header.h 文件的路径对不对

image

我没改,直接编译的
截屏2023-05-05 10 34 03

看一下你的 Xcode 版本,是最新的吗
image

对,14.3

没头绪,问了下 ChatGPT,不确定是不是 CocoaLumberjack 问题,你重新 pod install 一下吧,或者移除现有的 pod,再 pod install

image

我这里这个显示是红色的,不知道有没有关系
截屏2023-05-05 12 16 40

一看你这个目录结构就不对 😓

你是不是打开的 Easydict.xcodeproj ? pod 项目要打开 Easydict.xcworkspace

image

不好意思,第一次接触 pod 项目😓

这里是断点的结果 截屏2023-05-05 12 45 35

2023-05-05 12:42:55.404551+0800 Easydict-Debug[52452:2397065] [MMLog ● 75 ● I] +[MMManagerForLog sharedDDLog]_block_invoke ●
=========>
🚀 com.izual.Easydict-debug(1.3.0)[15] 启动 MMLog(Defalut)...

日志文件夹:
/Users/jerry/Library/Caches/com.izual.Easydict-debug/MMLogs/Default
<=========
2023-05-05 12:42:55.405475+0800 Easydict-Debug[52452:2397064] [AppDelegate ● 28 ● I] -[AppDelegate applicationDidFinishLaunching:] ● 程序启动
2023-05-05 12:42:55.443618+0800 Easydict-Debug[52452:2397060] [EZWindowManager ● 76 ● V] -[EZWindowManager setup] ● [
-1
]
2023-05-05 12:42:55.444547+0800 Easydict-Debug[52452:2397042] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2023-05-05 12:42:55.444858+0800 Easydict-Debug[52452:2397042] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2023-05-05 12:42:55.445062+0800 Easydict-Debug[52452:2397042] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2023-05-05 12:42:55.445260+0800 Easydict-Debug[52452:2397042] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2023-05-05 12:42:55.448385+0800 Easydict-Debug[52452:2397042] [default] CGSWindowShmemCreateWithPort failed on port 0
2023-05-05 12:42:55.973262+0800 Easydict-Debug[52452:2397042] [Window] Warning: Window NSMenuWindowManagerWindow 0x12460e570 ordered front from a non-active application and may order beneath the active application's windows.
2023-05-05 12:42:56.508575+0800 Easydict-Debug[52452:2397065] [EZStatusItem ● 143 ● V] -[EZStatusItem preferenceAction:] ● 偏好设置
2023-05-05 12:42:56.519330+0800 Easydict-Debug[52452:2397042] [NSToolbarItem] NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
2023-05-05 12:42:56.519376+0800 Easydict-Debug[52452:2397042] [NSToolbarItem] NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
2023-05-05 12:42:56.519729+0800 Easydict-Debug[52452:2397042] [NSToolbarItem] NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
2023-05-05 12:42:56.519753+0800 Easydict-Debug[52452:2397042] [NSToolbarItem] NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
2023-05-05 12:42:56.536370+0800 Easydict-Debug[52452:2397042] [NSToolbarItem] NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
2023-05-05 12:42:56.536402+0800 Easydict-Debug[52452:2397042] [NSToolbarItem] NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
2023-05-05 12:42:56.536673+0800 Easydict-Debug[52452:2397042] [NSToolbarItem] NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
2023-05-05 12:42:56.536698+0800 Easydict-Debug[52452:2397042] [NSToolbarItem] NSToolbarItem.minSize and NSToolbarItem.maxSize methods are deprecated. Usage may result in clipping of items. It is recommended to let the system measure the item automatically using constraints.
2023-05-05 12:42:56.547050+0800 Easydict-Debug[52452:2397042] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2023-05-05 12:42:56.547340+0800 Easydict-Debug[52452:2397042] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2023-05-05 12:42:56.547455+0800 Easydict-Debug[52452:2397042] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2023-05-05 12:42:56.547542+0800 Easydict-Debug[52452:2397042] [general] 'NSKeyedUnarchiveFromData' should not be used to for un-archiving and will be removed in a future release
2023-05-05 12:42:56.561065+0800 Easydict-Debug[52452:2397042] Metal API Validation Enabled
2023-05-05 12:42:56.598214+0800 Easydict-Debug[52452:2397042] [Window] Warning: Window NSWindow 0x134655100 ordered front from a non-active application and may order beneath the active application's windows.
2023-05-05 12:42:58.603691+0800 Easydict-Debug[52452:2397061] [EZWindowManager ● 782 ● V] -[EZWindowManager closeWindow] ● Close window
2023-05-05 12:42:58.604978+0800 Easydict-Debug[52452:2397065] [EZWindowManager ● 712 ● V] -[EZWindowManager closeFloatingWindow] ● close floating window: (null)
2023-05-05 12:43:05.595917+0800 Easydict-Debug[52452:2397065] [EZEventMonitor ● 365 ● V] -[EZEventMonitor isAccessibilityTrusted] ● isTrusted: 1
2023-05-05 12:43:05.632375+0800 Easydict-Debug[52452:2397063] [EZEventMonitor ● 302 ● I] -[EZEventMonitor getSelectedTextByAuxiliary:] ● Can't get selected text: -25205
(lldb)

确认一下,这是你在 Pages 中无法取词的日志,error 是 -25205 ?

看看你的 Pages bundle id 是不是 com.apple.iWork.Pages

是的,bundle id com.apple.iWork.Pages
截屏2023-05-05 15 55 28
又重新跑了一下,error是 -25205

Please debug, this is what Xcode shows me 2023-05-05 15:58:53.734059+0800 Easydict-Debug[61284:2484476] [EZEventMonitor ● 302 ● I] -[EZEventMonitor getSelectedTextByAuxiliary:] ● Can't get selected text: -25205

我在最新的 dev 分支把 Pages 加入了白名单,你测一下看行不行,以及是否会对别的应用造成影响。

测试了下最新的 dev,Pages 还是不行,可能是我自己的问题 😣
Xcode 还是会有报错,我分别在 Keynote 和 Numbers 中测试,也是会出现同样的问题

2023-05-06 07:17:04.757162+0800 Easydict-Debug[79486:2780209] [EZEventMonitor ● 173 ● V] -[EZEventMonitor getSelectedText:completion:]_block_invoke ● AXError: -25205

不不,AXError: -25205 这个是日志提示,是正常的,表示某些应用不支持常规的 Auxiliary 取词,所以这种情况就需要白名单,对白名单中的应用实行备用方法——模拟快捷键 Cmd+C 方式取词。

这个你不用管,你只要确定用最新的代码,能够在 Pages 等应用中能够取词就行了。

这个问题不知道为什么 build 不了,好像是有道的 API
截屏2023-05-07 00 08 38

你截全屏看一下,项目里好像没有用这个 JS 文件,另外,你这个路径显示也不太对 🧐

好像是有文件引用问题,忘记移除了 🥲 我更新了 dev 代码,你再试一下。

这回成功了!感谢,一起不好用的还有 iWork 三件套,还是不理解为什么 iWork 会不好用,可能是我 macOS 版本问题
我想这个 issue 要不要先不关,看看别人有没有同样的问题
截屏2023-05-07 00 21 56

你的 Numbers 和 Keynote 也还不能取词吗? 我这边显示它们都是正常的。

如果是,看一下 error 是不是一样,参考这个 commit 23742ec , 那也可以在这里加一下它们的 bundle id

@"com.apple.iWork.Pages", // Pages, FIX: https://github.com/tisfeng/Easydict/issues/84#issuecomment-1535885832

刚刚试了一下,我这边加上 bundle id 就好用了

行吧。感觉你的电脑配置环境可能有点不一样,你可以把你所有的应用都测一遍,列出有问题的应用,我看看能不能找出问题。

如果有问题,也可以都按下面这种 error 和 bundle id 字典对应方式添加,然后在 dev 上提一个 PR

        // Some App return kAXErrorAttributeUnsupported but actually has selected text.
        @(kAXErrorAttributeUnsupported) : @[
            @"com.sublimetext.4", // Sublime Text
            @"com.microsoft.Word", // Word
            @"com.apple.iWork.Pages", // Pages, FIX: https://github.com/tisfeng/Easydict/issues/84#issuecomment-1535885832
        ],

收到🫡,非常感谢🙏🏻,我会在所有的应用中进行测试然后 PR

刚刚测试了所有应用,下面这些不能正常取词

  • 微信
  • 图书
  • 无边记

很有意思的是,Word 不支持但是 PPT 和 Excel 都可以,这三个我都是 MAS 版本

有点神奇,我这边发现无边记可以取词,微信和图书也不能正常取词 🥲

另外,之前我好像测试过微信,那时候可以,具体记不太清了。

看一下你的系统版本,我的是 13.4 Beta版(22F5059b)

我的是 13.3.1 (a) (22E772610a)

无边记测试了三种,形状、文本、便签都不好用,目前看不统一的都是 Apple 自带的 app 🤔

然后如果取这里的文本框是可以的😂
SCR-20230507-knyi

可能是因为苹果自家的应用整了些非常规的技术,比如私有 API 之类的,这些对 Auxiliary 取词都不友好。

另外,我重新测了一下图书 iBooks,发现把它加入白名单不合适,因为使用模拟快捷键方式取词会导致应用本身的划词弹窗自动消失,手动 Cmd+C 复制也会。 顺便看了一下 PopClip,果然,它也没在 iBooks 上工作。

image

原来如此,我回头身边有其他设备的时候再试试

zausa commented

在 foxit pdf reader上幾個翻譯都不起作用
safari 上使用正常設定上應該沒有問題
找了好久實在找不到這篇的解方的檔案在哪
附上連結:https://apps.apple.com/tw/app/foxit-pdf-reader/id1032155965?mt=12

log檔 :
[2023-07-11 14:59:22.557 ● AppDelegate ● 23 ● I] -[AppDelegate applicationDidFinishLaunching:] ● 程序启动
[2023-07-11 14:59:29.160 ● EZEventMonitor ● 451 ● I] -[EZEventMonitor getSelectedTextByAccessibility:] ● --> Accessibility getText:
[2023-07-11 14:59:29.160 ● EZEventMonitor ● 601 ● I] -[EZEventMonitor shouldUseSimulatedKey:error:] ● Fallback, need to add it to allowed app error list dict
[2023-07-11 14:59:29.160 ● EZEventMonitor ● 602 ● I] -[EZEventMonitor shouldUseSimulatedKey:error:] ● 0, com.foxitsoftware.FoxitReaderLite, Foxit PDF Reader
[2023-07-11 14:59:31.593 ● EZEventMonitor ● 451 ● I] -[EZEventMonitor getSelectedTextByAccessibility:] ● --> Accessibility getText:
[2023-07-11 14:59:31.593 ● EZEventMonitor ● 601 ● I] -[EZEventMonitor shouldUseSimulatedKey:error:] ● Fallback, need to add it to allowed app error list dict
[2023-07-11 14:59:31.593 ● EZEventMonitor ● 602 ● I] -[EZEventMonitor shouldUseSimulatedKey:error:] ● 0, com.foxitsoftware.FoxitReaderLite, Foxit PDF Reader
[2023-07-11 15:01:26.963 ● EZEventMonitor ● 451 ● I] -[EZEventMonitor getSelectedTextByAccessibility:] ● --> Accessibility getText:
[2023-07-11 15:01:26.963 ● EZEventMonitor ● 601 ● I] -[EZEventMonitor shouldUseSimulatedKey:error:] ● Fallback, need to add it to allowed app error list dict
[2023-07-11 15:01:26.963 ● EZEventMonitor ● 602 ● I] -[EZEventMonitor shouldUseSimulatedKey:error:] ● 0, com.foxitsoftware.FoxitReaderLite, Foxit PDF Reader

Hi @zausa,

我下载了一个 Mac App Store 版本的 Foxit PDF Reader,Easydict 是可以正常取词的呀

  • 应用版本 App Store 11.1.2
  • bundle ID com.foxitsoftware.FoxitReaderLite

幾個翻譯都不起作用

你说的翻译不起作用是指什么呢

可能这也属于那种比较奇怪的应用 🤔 在我电脑上测试,Foxit PDF Reader 也不能正常取词,类型是 kAXErrorSuccess,我刚把它加到白名单里了 cdf9355

@zausa 感谢反馈,下个版本更新会修复。

zausa commented

感謝~ 我的狀況和這樓狀況也是一樣的 主要是划詞翻譯和迷你小窗 選取文本後按下熱鍵會沒有文本出現在輸入框內

@zausa 不不,我这边测试只有鼠标划词会失败,而快捷键取词是成功的,并且理论上,快捷键取词功能在任何应用都应该是可以正常工作的。

请先确保你的 Easydict 是最新版本,如果在你电脑上出现异常,麻烦提供详细的信息,包括但不限于测试步骤,触发方式,导出日志等等, 最好也提供一个操作录屏。

zausa commented

抱歉沒說清楚 快捷鍵取詞功能時有時無
我的Easydict 是最新版本
我再研究一下是否有可復現的步驟

zausa commented

後來嘗試後發現是在每次第一次開啟軟體的第一次使用滑詞翻譯功能都會失敗
但在我影片的這篇文檔卻怎麼都翻譯不過
操作影片 文檔 和 log 都在連結中
link

看了一下日志,也没啥问题。在我电脑上测试,没有出现问题。

目前代码已经对 Foxit PDF Reader 进行了优化,下个版本你在测试一下吧。

你的 Numbers 和 Keynote 也还不能取词吗? 我这边显示它们都是正常的。

如果是,看一下 error 是不是一样,参考这个 commit 23742ec , 那也可以在这里加一下它们的 bundle id

@"com.apple.iWork.Pages", // Pages, FIX: https://github.com/tisfeng/Easydict/issues/84#issuecomment-1535885832

您好,我这面试了一下,目前mac三件套能使用,但是我的图书软件不能使用。现在我的系统版本是Sanoma 14.2.

@RichardKimber 参考前面 #84 (comment) ,之前 macOS 13 发现图书 App 不适合使用模拟快捷键方式取词。

但有点奇怪,现在 macOS 14.1.1 测试鼠标划词后,图书 App 不会自动弹出标注框了,可能是苹果修改了操作逻辑。

另外,在我电脑上调试,目前图书 App 使用 Accessibility 取词仍会失败,但却有下面两种失败信息,很奇怪,我没有找到规律。

[EZEventMonitor ● 515 ● I] -[EZEventMonitor getSelectedTextByAccessibility:] ● --> Accessibility success, getText:
[EZEventMonitor ● 520 ● I] -[EZEventMonitor getSelectedTextByAccessibility:] ● Accessibility error: -25205

不确定是不是只有我电脑上会这样,方便的话麻烦你们也测试一下。

如果确定图书 App 在 macOS 14+ 不会自动弹出标注框,那感觉可以加一下,Accessibility 取词失败就 Cmd + C。

如果确定图书 App 在 macOS 14+ 不会自动弹出标注框

我这边虚拟机 14.1.1 上不会自动弹

你可以测一下 macOS 13 吗,也看一下图书 App 取词失败时的日志。

[EZEventMonitor ● 515 ● I] -[EZEventMonitor getSelectedTextByAccessibility:] ● --> Accessibility success, getText:
[EZEventMonitor ● 520 ● I] -[EZEventMonitor getSelectedTextByAccessibility:] ● Accessibility error: -25205

我这边在 13.6.2 上也是这两个来回出现,但是没找到触发条件是什么 Accessibility success, getText: 出现相对多一些

ok,你分别在 macOS 13 和 14 都测一下:

  1. 划词是否会自动弹窗
  2. 取词失败时的日志

ok,你分别在 macOS 13 和 14 都测一下:

  1. 划词是否会自动弹窗
  2. 取词失败时的日志

我稍晚一些去测

@tisfeng 我的虚拟机不支持Apple ID登录,不能直接MAS下载Xcode,回头我看看有什么其他方法再测

macOS Sonoma ,edge 浏览器页面,划词不弹出图标,快捷键可以弹出图标。

edge 之前测试过,正常来说只要为 Easydict 开启了【隐私与安全性-->辅助功能】权限,那就支持 Accessibility 取词。

但某些特殊情况下 Accessibility 取词可能会失败 #85 (comment) ,建议开启浏览器的【允许 Apple 事件中的 JavaScript】功能。

另外,某些奇怪问题可能导致【隐私与安全性-->辅助功能】权限失效,建议删除,重新加一下。

anki里不能 滑词翻译,我之前用popClip也会有这个问题,他们说是因为 调用了第三方库 导致的 https://forum.popclip.app/t/popclip-not-working-in-anki/563/7 ,始终无法解决,
我以为我们这软件支持,没想到也不行,
不知道开发人员有没有用过 sider 客户端,这个工具就能在 anki中滑词出现浮窗,
为啥呢

我下载测试了一下 anki macOS 12+ (Apple Silicon, 23.12.1 Qt6),鼠标取词好像没有问题?

image

我下载测试了一下 anki macOS 12+ (Apple Silicon, 23.12.1 Qt6),鼠标取词好像没有问题?

image

好像是Qt-5版本会有这个问题。(我由于某些特殊原因 不能升级到 Qt-6)....
我看TTime滑词会出现一个悬浮球,

试了一下 Qt-5 版本,确实不支持系统 Accessibility API 取词,但只要在设置中开启【强制划词】,也能成功的。

image

找到了,太感谢了
另外请教一个问题,我电脑系统现在的语言是英文,如何将这款软件默认为中文啊,
下面图片中的首选语言和 第二选择语言是什么意思啊,互换后也没生效
image

应用内切换语言还在开发中 #348 ,目前可以在【设置-语言与地区】中修改。

image

#131 (comment)

翻译时,如果用户没有指定目标翻译语言,则会根据输入文本识别的语言和偏好语言,来自动选择目标翻译语言,具体规则如下:

如果输入文本语言不是第一语言,则目标翻译语言为第一语言。
如果输入文本语言是第一语言,则目标翻译语言为第二语言。

问题描述
在 WPS 中无法正常使用划词翻译功能,更新到最新版后功能失效,之前[v2.7.2] 版本可用。

重现步骤
启动上述应用
选中文本
使用快捷键划词翻译
看到文本框中没有内容
期望结果
可以在上述应用中正常使用划词翻译

应用版本:
WPS 6.11.0(8885)
Easydict 2.9.0

@danaquentin 有尝试开始剪贴板强制取词吗?设置 -> 通用 -> 鼠标查询

@danaquentin 有尝试开始剪贴板强制取词吗?设置 -> 通用 -> 鼠标查询

强制取词可以

问题描述

在 Safari 和 Edge 的 PDF Preview 中无法正常使用划词翻译功能。(已开启强制取词和Allow Javascript From Apple Event )

选中文本后可以正常复制到剪切板。

重现步骤

  1. 启动上述应用
  2. 使用快捷键或者触控板选中文本后划词翻译,不会弹出查询图标
  3. 同时弹出窗口文本框中没有内容
image

期望结果

可以在上述情景中正常使用划词翻译。

应用版本

Easydict 2.9.0

问题描述

在 Safari 和 Edge 的 PDF Preview 中无法正常使用划词翻译功能。(已开启强制取词和Allow Javascript From Apple Event )

选中文本后可以正常复制到剪切板。

重现步骤

  1. 启动上述应用
  2. 使用快捷键或者触控板选中文本后划词翻译,不会弹出查询图标
  3. 同时弹出窗口文本框中没有内容
image ### 期望结果 可以在上述情景中正常使用划词翻译。

应用版本

Easydict 2.9.0 易字典2.9.0

这样简单描述,无法确定问题所在。

请另外单独开 issue,记得附上运行日志,方便开发者排查问题。

在福昕pdf阅读器中划词功能好像完全没用

我没有用过福昕pdf阅读器,某些应用对系统的取词功能不友好,可能存在问题。

请确认开启了强制取词,并尝试一下使用菜单栏动作复制取词。如果还是不行,请单独开 issue,记得附上运行日志。

调试发现,福昕PDF阅读器显示系统取词成功,但实际没有获取到选中文本。

需要修改一下代码,改用强制取词。下个版本将会修复。

我下载测试了一下 anki macOS 12+ (Apple Silicon, 23.12.1 Qt6),鼠标取词好像没有问题?

image

@tisfeng Could you check again if it works on Anki?

I think it doesn't work anymore in macOS 15.3 and Anki 24.11 Qt6

Image

I already switched on Force Get Selected Text

Image

我下载测试了一下 anki macOS 12+ (Apple Silicon, 23.12.1 Qt6),鼠标取词好像没有问题?
image

@tisfeng Could you check again if it works on Anki?

I think it doesn't work anymore in macOS 15.3 and Anki 24.11 Qt6

Image

I already switched on Force Get Selected Text

Image

I can't understand this issue if it lacks detail.

Please open a new issue with Runtime logs, otherwise, we cannot determine this problem.

If you encounter an application that cannot select words, you can open an issue to solve it #84

I was from docs to resolve problem when I select text in Anki.

Anyway. It works now after changing Force Get Selected Text Type option to Simulated Shortcut Copy. Here are logs each option.

Menu Bar Action Copy (NOT WORK):

Image

Simulated Shortcut Copy (WORK):

Image

ok, maybe Anki do not support Menu Bar Action Copy.