yuhldr / ldr-translate

一个linux/ubuntu版本的翻译软件,主打文献翻译(a translate app for ubuntu/linux),使用Gtk3开发,python语言;国内看这里:https://gitee.com/yuhldr/ldr-translate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

youdao翻译问题,手动编译问题与建议

lzr1264823628 opened this issue · comments

背景

系统:ubuntu18
版本:1.7.1 2023年 02月 27日 星期一 13:13:43 CST

问题

编译问题

指令make gtk

    cp gui/gtk/*.ui build/gtk/ldr-translate/opt/ldr-translate/
    cp gui/gtk/*.py build/gtk/ldr-translate/opt/ldr-translate/

描述
此处的复制路径貌似设置错误,影响make install,导致后来的/opt/ldr-translate文件夹中缺少了*.py 与 *.ui

youdao 翻译

描述:对于youdao翻译返回值的组合处理错误,会导致结果只有一句。

diff --git a/api/server/youdao.py b/api/server/youdao.py
index d19aae1..35d6e1f 100644
--- a/api/server/youdao.py
+++ b/api/server/youdao.py
@@ -24,8 +24,8 @@ def translate_text(s, from_lang="auto", to_lang=""):
             s1 = "翻译错误,试试其他引擎?"
         else:
             print(result["translateResult"])
-            for trans_result in result["translateResult"]:
-                s1 += trans_result[0]["tgt"] + "\n"
+            for trans_result in result["translateResult"][0]:
+                s1 += trans_result["tgt"] + "\n"
     else:
         s1 = "请求错误:" + request.content

建议

添加全局快捷键
使用keybinder

diff --git a/gui/gtk/main.py b/gui/gtk/main.py
index 99be1b9..5835bcf 100644
--- a/gui/gtk/main.py
+++ b/gui/gtk/main.py
@@ -14,6 +14,8 @@ import gi
 
 from utils import locales, version, config
 from utils.locales import t_ui
+gi.require_version('Keybinder', '3.0')
+from gi.repository import Keybinder
 
 try:
     gi.require_version('AyatanaAppIndicator3', '0.1')
@@ -155,6 +157,12 @@ class LdrTranslate(Gtk.Application):
             a = None
         self.translate_win.copy_auto_translate(a)
 
+    def key_binder_callback(self, key_group, clipboard):
+        if self.translate_win is None or self.translate_win.is_hide:
+            self.translate_win = Translate()
+            self.translate_win.open()
+        self.translate_win.copy_auto_translate(clipboard)
+
     def get_clipboard(self):
         if self.auto_translate == 0:
             return self.clip_copy
@@ -176,7 +184,9 @@ class LdrTranslate(Gtk.Application):
 if __name__ == "__main__":
 
     app = LdrTranslate()
-
+    key_group = "<Ctrl><Alt>L"
+    Keybinder.init()
+    Keybinder.bind(key_group, app.key_binder_callback, app.clip_select)
     try:
         Gtk.main()
     except KeyboardInterrupt:
commented

你直接提交一个 Pull requests,我这边测试合并一下