From e2e9f48c1e6891a0ff79fc53795fb88beb606d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Sat, 14 Dec 2024 18:21:46 +0800 Subject: [PATCH] . --- .github/scripts/build_lunatranslator.py | 6 +-- .gitignore | 2 +- cpp/version.cmake | 2 +- py/LunaTranslator/gui/setting_about.py | 4 +- py/LunaTranslator/gui/usefulwidget.py | 2 +- py/LunaTranslator/ocrengines/local.py | 52 ++++++++++++------------- py/files/lang/ar.json | 3 +- py/files/lang/cht.json | 3 +- py/files/lang/cs.json | 3 +- py/files/lang/de.json | 3 +- py/files/lang/en.json | 3 +- py/files/lang/es.json | 3 +- py/files/lang/fr.json | 3 +- py/files/lang/it.json | 3 +- py/files/lang/ja.json | 3 +- py/files/lang/ko.json | 3 +- py/files/lang/nl.json | 3 +- py/files/lang/pl.json | 3 +- py/files/lang/pt.json | 3 +- py/files/lang/ru.json | 3 +- py/files/lang/sv.json | 3 +- py/files/lang/th.json | 3 +- py/files/lang/tr.json | 3 +- py/files/lang/uk.json | 3 +- py/files/lang/vi.json | 3 +- py/files/lang/zh.json | 3 +- 26 files changed, 74 insertions(+), 54 deletions(-) diff --git a/.github/scripts/build_lunatranslator.py b/.github/scripts/build_lunatranslator.py index 3b832f73..870c9037 100644 --- a/.github/scripts/build_lunatranslator.py +++ b/.github/scripts/build_lunatranslator.py @@ -207,9 +207,9 @@ def downloadCurl(): def downloadOCRModel(): os.chdir(rootDir + "\\files") - if not os.path.exists("ocr"): - os.mkdir("ocr") - os.chdir("ocr") + if not os.path.exists("ocrmodel"): + os.mkdir("ocrmodel") + os.chdir("ocrmodel") subprocess.run(f"curl -LO {mylinks['ocr_models']['ja.zip']}") subprocess.run(f"7z x ja.zip") os.remove(f"ja.zip") diff --git a/.gitignore b/.gitignore index d0acfa9a..222dce2a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ py/.q_vscode_style py/userconfig py/cache py/chrome_cache -py/files/ocr +py/files/ocrmodel py/files/plugins py/files/themes py/run37.bat diff --git a/cpp/version.cmake b/cpp/version.cmake index 43908b5e..b72fc097 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 6) set(VERSION_MINOR 11) -set(VERSION_PATCH 6) +set(VERSION_PATCH 7) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) diff --git a/py/LunaTranslator/gui/setting_about.py b/py/LunaTranslator/gui/setting_about.py index 23866975..f4f84c97 100644 --- a/py/LunaTranslator/gui/setting_about.py +++ b/py/LunaTranslator/gui/setting_about.py @@ -251,7 +251,7 @@ def versionlabelmaybesettext(self, x): def solvelinkitems(grid, source): name = source["name"] link = source["link"] - grid.append([((name), 1, ""), (makehtml(link), 2, "link")]) + grid.append([name, (makehtml(link), 2, "link")]) def resourcegrid(self, l): @@ -265,7 +265,7 @@ def resourcegrid(self, l): __grid = [] for link in source["links"]: - solvelinkitems(__grid, link) + __grid.append([link["name"], (makehtml(link["link"]), 2, "link")]) grid.append( [ ( diff --git a/py/LunaTranslator/gui/usefulwidget.py b/py/LunaTranslator/gui/usefulwidget.py index c3ce2a18..f1db522e 100644 --- a/py/LunaTranslator/gui/usefulwidget.py +++ b/py/LunaTranslator/gui/usefulwidget.py @@ -1810,7 +1810,7 @@ def automakegrid(grid: QGridLayout, lis, save=False, savelist=None): elif len(item) == 3: wid, cols, arg = item if type(wid) == str: - wid = LLabel(wid) + wid = QLabel(wid) if arg == "link": wid.setOpenExternalLinks(True) elif arg == "group": diff --git a/py/LunaTranslator/ocrengines/local.py b/py/LunaTranslator/ocrengines/local.py index 9f7b920b..2bb7866c 100644 --- a/py/LunaTranslator/ocrengines/local.py +++ b/py/LunaTranslator/ocrengines/local.py @@ -88,18 +88,29 @@ class ocrwrapper: _OcrDestroy(self.pOcrObj) +def findmodel(langcode): + + check = lambda path: ( + os.path.exists(path + "/det.onnx") + and os.path.exists(path + "/rec.onnx") + and os.path.exists(path + "/dict.txt") + ) + for path in [ + "./files/ocrmodel/{}".format(langcode), + "cache/ocrmodel/{}".format(langcode), + ]: + if check(path): + return path + + def getallsupports(): - langs = [] - for f in os.listdir("./files/ocr"): - path = "./files/ocr/{}".format(f) - if not ( - os.path.exists(path + "/det.onnx") - and os.path.exists(path + "/rec.onnx") - and os.path.exists(path + "/dict.txt") - ): - continue - langs.append(f) - return langs + validlangs = [] + for d in ["./files/ocrmodel", "cache/ocrmodel"]: + if os.path.exists(d): + for lang in os.listdir(d): + if findmodel(lang): + validlangs.append(lang) + return validlangs def dodownload(combo: QComboBox, allsupports: list): @@ -117,7 +128,7 @@ def doinstall(self, combo: QComboBox, allsupports: list, parent, callback): return try: with zipfile.ZipFile(fn) as zipf: - zipf.extractall("files/ocr") + zipf.extractall("cache/ocrmodel") getQMessageBox(self, "成功", "安装成功") callback() except: @@ -167,22 +178,11 @@ class OCR(baseocr): self._savelang = None self.checkchange() - def checklangvalid(self, langcode): - path = "./files/ocr/{}".format(langcode) - return ( - os.path.exists(path + "/det.onnx") - and os.path.exists(path + "/rec.onnx") - and os.path.exists(path + "/dict.txt") - ) - def checkchange(self): if self._savelang == self.srclang: return if self.srclang == "auto": - validlangs = [] - for lang in os.listdir("./files/ocr"): - if self.checklangvalid(lang): - validlangs.append(lang) + validlangs = getallsupports() if len(validlangs) == 1: uselang = validlangs[0] elif len(validlangs) == 0: @@ -190,7 +190,7 @@ class OCR(baseocr): else: self.raise_cant_be_auto_lang() else: - if self.checklangvalid(self.srclang): + if findmodel(self.srclang): uselang = self.srclang else: raise Exception( @@ -206,7 +206,7 @@ class OCR(baseocr): ) self._ocr = None - path = "./files/ocr/{}".format(uselang) + path = findmodel(uselang) self._ocr = ocrwrapper( path + "/det.onnx", path + "/rec.onnx", path + "/dict.txt" ) diff --git a/py/files/lang/ar.json b/py/files/lang/ar.json index b3836b4f..0e968d0e 100644 --- a/py/files/lang/ar.json +++ b/py/files/lang/ar.json @@ -754,5 +754,6 @@ "截取指定行数": "اعتراض عدد محدد من الصفوف", "截取末尾": "اعتراض نهاية", "更新记录": "تحديث السجلات", - "打开选择文本窗口": "فتح نافذة اختيار النص" + "打开选择文本窗口": "فتح نافذة اختيار النص", + "成功": "النجاح ." } \ No newline at end of file diff --git a/py/files/lang/cht.json b/py/files/lang/cht.json index d892f242..28a68879 100644 --- a/py/files/lang/cht.json +++ b/py/files/lang/cht.json @@ -754,5 +754,6 @@ "截取指定行数": "截取指定行數", "截取末尾": "截取末尾", "更新记录": "更新記錄", - "打开选择文本窗口": "打開選擇文字視窗" + "打开选择文本窗口": "打開選擇文字視窗", + "成功": "成功" } \ No newline at end of file diff --git a/py/files/lang/cs.json b/py/files/lang/cs.json index aa74d878..03430de4 100644 --- a/py/files/lang/cs.json +++ b/py/files/lang/cs.json @@ -754,5 +754,6 @@ "截取指定行数": "Extrahovat zadaný počet řádků", "截取末尾": "Střih do konce", "更新记录": "Aktualizovat záznam", - "打开选择文本窗口": "Otevřít textové okno výběru" + "打开选择文本窗口": "Otevřít textové okno výběru", + "成功": "úspěch" } \ No newline at end of file diff --git a/py/files/lang/de.json b/py/files/lang/de.json index 49eee4a6..e6441ed6 100644 --- a/py/files/lang/de.json +++ b/py/files/lang/de.json @@ -754,5 +754,6 @@ "截取指定行数": "Die angegebene Anzahl von Zeilen extrahieren", "截取末尾": "Bis zum Ende geschnitten", "更新记录": "Datensatz aktualisieren", - "打开选择文本窗口": "Öffnen des Auswahltextfensters" + "打开选择文本窗口": "Öffnen des Auswahltextfensters", + "成功": "Erfolg" } \ No newline at end of file diff --git a/py/files/lang/en.json b/py/files/lang/en.json index bf8dbbb3..b7868f18 100644 --- a/py/files/lang/en.json +++ b/py/files/lang/en.json @@ -754,5 +754,6 @@ "截取指定行数": "Extract the specified number of rows", "截取末尾": "Cut to the end", "更新记录": "Update Record", - "打开选择文本窗口": "Open the selection text window" + "打开选择文本窗口": "Open the selection text window", + "成功": "success" } \ No newline at end of file diff --git a/py/files/lang/es.json b/py/files/lang/es.json index ebe35673..9f6d290c 100644 --- a/py/files/lang/es.json +++ b/py/files/lang/es.json @@ -754,5 +754,6 @@ "截取指定行数": "Interceptar el número de líneas especificadas", "截取末尾": "Fin de la interceptación", "更新记录": "Actualización de registros", - "打开选择文本窗口": "Abrir la ventana de texto de selección" + "打开选择文本窗口": "Abrir la ventana de texto de selección", + "成功": "éxito" } \ No newline at end of file diff --git a/py/files/lang/fr.json b/py/files/lang/fr.json index bd2aa06c..b5a278cc 100644 --- a/py/files/lang/fr.json +++ b/py/files/lang/fr.json @@ -754,5 +754,6 @@ "截取指定行数": "Intercepte le nombre de lignes spécifié", "截取末尾": "Fin de l'interception", "更新记录": "Mettre à jour les enregistrements", - "打开选择文本窗口": "Ouvrir la fenêtre sélectionner le texte" + "打开选择文本窗口": "Ouvrir la fenêtre sélectionner le texte", + "成功": "Succès" } \ No newline at end of file diff --git a/py/files/lang/it.json b/py/files/lang/it.json index ddda534c..4edc7754 100644 --- a/py/files/lang/it.json +++ b/py/files/lang/it.json @@ -754,5 +754,6 @@ "截取指定行数": "Estrarre il numero specificato di righe", "截取末尾": "Taglia fino alla fine", "更新记录": "Aggiorna record", - "打开选择文本窗口": "Apri la finestra del testo di selezione" + "打开选择文本窗口": "Apri la finestra del testo di selezione", + "成功": "successo" } \ No newline at end of file diff --git a/py/files/lang/ja.json b/py/files/lang/ja.json index a8ef1a1f..318cc6d5 100644 --- a/py/files/lang/ja.json +++ b/py/files/lang/ja.json @@ -754,5 +754,6 @@ "截取指定行数": "指定した行数を切り取る", "截取末尾": "末尾を切り取る", "更新记录": "レコードの更新", - "打开选择文本窗口": "テキストの選択ウィンドウを開く" + "打开选择文本窗口": "テキストの選択ウィンドウを開く", + "成功": "成功" } \ No newline at end of file diff --git a/py/files/lang/ko.json b/py/files/lang/ko.json index 980bac3e..18e233ee 100644 --- a/py/files/lang/ko.json +++ b/py/files/lang/ko.json @@ -754,5 +754,6 @@ "截取指定行数": "지정된 행 수 캡처", "截取末尾": "끝을 가로채다", "更新记录": "레코드 업데이트", - "打开选择文本窗口": "텍스트 선택 창 열기" + "打开选择文本窗口": "텍스트 선택 창 열기", + "成功": "성공" } \ No newline at end of file diff --git a/py/files/lang/nl.json b/py/files/lang/nl.json index eafe6a90..b00e0ea8 100644 --- a/py/files/lang/nl.json +++ b/py/files/lang/nl.json @@ -754,5 +754,6 @@ "截取指定行数": "Het opgegeven aantal rijen uitpakken", "截取末尾": "Snijd tot het einde", "更新记录": "Record bijwerken", - "打开选择文本窗口": "Het selectietekstvenster openen" + "打开选择文本窗口": "Het selectietekstvenster openen", + "成功": "succes" } \ No newline at end of file diff --git a/py/files/lang/pl.json b/py/files/lang/pl.json index afffd7bf..15aee9ae 100644 --- a/py/files/lang/pl.json +++ b/py/files/lang/pl.json @@ -754,5 +754,6 @@ "截取指定行数": "Wyciągnij określoną liczbę wierszy", "截取末尾": "Cięcie do końca", "更新记录": "Aktualizuj rekord", - "打开选择文本窗口": "Otwórz okno tekstowe zaznaczenia" + "打开选择文本窗口": "Otwórz okno tekstowe zaznaczenia", + "成功": "sukces" } \ No newline at end of file diff --git a/py/files/lang/pt.json b/py/files/lang/pt.json index 708ab38e..415d76eb 100644 --- a/py/files/lang/pt.json +++ b/py/files/lang/pt.json @@ -754,5 +754,6 @@ "截取指定行数": "Extrair o número especificado de linhas", "截取末尾": "Cortar até ao fim", "更新记录": "Actualizar o Registo", - "打开选择文本窗口": "Abrir a janela de texto da selecção" + "打开选择文本窗口": "Abrir a janela de texto da selecção", + "成功": "sucesso" } \ No newline at end of file diff --git a/py/files/lang/ru.json b/py/files/lang/ru.json index bddc4fd6..9038075e 100644 --- a/py/files/lang/ru.json +++ b/py/files/lang/ru.json @@ -754,5 +754,6 @@ "截取指定行数": "Перехватить указанное число строк", "截取末尾": "Отрезать конец", "更新记录": "Обновить запись", - "打开选择文本窗口": "Открыть окно выбора текста" + "打开选择文本窗口": "Открыть окно выбора текста", + "成功": "Успех" } \ No newline at end of file diff --git a/py/files/lang/sv.json b/py/files/lang/sv.json index 17e58bbb..8bd8371f 100644 --- a/py/files/lang/sv.json +++ b/py/files/lang/sv.json @@ -754,5 +754,6 @@ "截取指定行数": "Extrahera angivet antal rader", "截取末尾": "Klipp till slutet", "更新记录": "Uppdatera post", - "打开选择文本窗口": "Öppna markeringstextfönstret" + "打开选择文本窗口": "Öppna markeringstextfönstret", + "成功": "framgång" } \ No newline at end of file diff --git a/py/files/lang/th.json b/py/files/lang/th.json index ef650ff5..5334e952 100644 --- a/py/files/lang/th.json +++ b/py/files/lang/th.json @@ -754,5 +754,6 @@ "截取指定行数": "สกัดกั้นจำนวนแถวที่ระบุ", "截取末尾": "ตัดตอนท้าย", "更新记录": "บันทึกการปรับปรุง", - "打开选择文本窗口": "เปิดหน้าต่างเลือกข้อความ" + "打开选择文本窗口": "เปิดหน้าต่างเลือกข้อความ", + "成功": "ความสำเร็จ" } \ No newline at end of file diff --git a/py/files/lang/tr.json b/py/files/lang/tr.json index 314ccc66..decab8df 100644 --- a/py/files/lang/tr.json +++ b/py/files/lang/tr.json @@ -754,5 +754,6 @@ "截取指定行数": "Belirtilen satır sayısını çıkart", "截取末尾": "Sonuna kesin.", "更新记录": "Kayıt Güncelle", - "打开选择文本窗口": "Seçim metin penceresini aç" + "打开选择文本窗口": "Seçim metin penceresini aç", + "成功": "başarılı" } \ No newline at end of file diff --git a/py/files/lang/uk.json b/py/files/lang/uk.json index c58c9303..69664736 100644 --- a/py/files/lang/uk.json +++ b/py/files/lang/uk.json @@ -754,5 +754,6 @@ "截取指定行数": "Extract the specified number of rows", "截取末尾": "Вирізати до кінця", "更新记录": "Оновити запис", - "打开选择文本窗口": "Відкрити текстове вікно вибору" + "打开选择文本窗口": "Відкрити текстове вікно вибору", + "成功": "успіх" } \ No newline at end of file diff --git a/py/files/lang/vi.json b/py/files/lang/vi.json index 47768b1f..245ad8da 100644 --- a/py/files/lang/vi.json +++ b/py/files/lang/vi.json @@ -754,5 +754,6 @@ "截取指定行数": "Chặn số dòng đã xác định", "截取末尾": "Kết thúc cắt", "更新记录": "Cập nhật hồ sơ", - "打开选择文本窗口": "Mở cửa sổ Select Text" + "打开选择文本窗口": "Mở cửa sổ Select Text", + "成功": "Thành công" } \ No newline at end of file diff --git a/py/files/lang/zh.json b/py/files/lang/zh.json index 3a8dc948..254e64d4 100644 --- a/py/files/lang/zh.json +++ b/py/files/lang/zh.json @@ -754,5 +754,6 @@ "截取指定行数": "", "截取末尾": "", "更新记录": "", - "打开选择文本窗口": "" + "打开选择文本窗口": "", + "成功": "" } \ No newline at end of file