From f104630ccb2a66cddad66e8f3f177614e74efe15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sat, 25 May 2024 01:37:53 +0800 Subject: [PATCH] pull/765 --- LunaTranslator/LunaTranslator/gui/showword.py | 22 ++++++++++++++++++- .../LunaTranslator/gui/translatorUI.py | 14 ++++++------ LunaTranslator/files/anki/back.html | 8 +++++-- LunaTranslator/files/anki/front.html | 8 +++++-- LunaTranslator/files/anki/style.css | 1 + .../files/defaultconfig/config.json | 3 ++- LunaTranslator/files/lang/ar.json | 4 +++- LunaTranslator/files/lang/cht.json | 4 +++- LunaTranslator/files/lang/en.json | 4 +++- LunaTranslator/files/lang/es.json | 4 +++- LunaTranslator/files/lang/fr.json | 4 +++- LunaTranslator/files/lang/it.json | 4 +++- LunaTranslator/files/lang/ja.json | 4 +++- LunaTranslator/files/lang/ko.json | 4 +++- LunaTranslator/files/lang/pl.json | 4 +++- LunaTranslator/files/lang/ru.json | 4 +++- LunaTranslator/files/lang/th.json | 4 +++- LunaTranslator/files/lang/tr.json | 4 +++- LunaTranslator/files/lang/uk.json | 4 +++- LunaTranslator/files/lang/vi.json | 4 +++- LunaTranslator/files/lang/zh.json | 3 ++- 21 files changed, 87 insertions(+), 28 deletions(-) diff --git a/LunaTranslator/LunaTranslator/gui/showword.py b/LunaTranslator/LunaTranslator/gui/showword.py index bcb351f5..ce0c2f50 100644 --- a/LunaTranslator/LunaTranslator/gui/showword.py +++ b/LunaTranslator/LunaTranslator/gui/showword.py @@ -294,12 +294,22 @@ class AnkiWindow(QWidget): remarks = self.remarks.toPlainText() example = self.example.toPlainText() + if globalconfig["ankiconnect"]["boldword"]: + if self.example.hiras is None: + self.example.hiras = gobject.baseobject.translation_ui.parsehira(example) + collect = [] + for hira in self.example.hiras: + if hira["orig"] == word or hira.get("origorig", None) == word: + collect.append(f'{hira["orig"]}') + else: + collect.append(hira["orig"]) + example = "".join(collect) ruby = self.ruby fields = { "word": word, "rubytext": ruby, "explain": explain, - "example_sentence": example, + "example_sentence": example.replace("\n", "
"), "remarks": remarks, } return fields @@ -401,6 +411,10 @@ class AnkiWindow(QWidget): _TR("自动截图"), getsimpleswitch(globalconfig["ankiconnect"], "autocrop"), ) + layout.addRow( + _TR("例句中加粗单词"), + getsimpleswitch(globalconfig["ankiconnect"], "boldword"), + ) layout.addRow( _TR("录音时模拟按键_1"), @@ -461,6 +475,12 @@ class AnkiWindow(QWidget): self.viewimagelabel = QLabel() self.editpath.textChanged.connect(self.wrappedpixmap) self.example = QPlainTextEdit() + self.example.hiras = None + + def __(): + self.example.hiras = None + + self.example.textChanged.connect(__) self.remarks = QPlainTextEdit() recordbtn1 = statusbutton(icons=["fa.microphone", "fa.stop"], colors=[""]) recordbtn1.statuschanged1.connect( diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index 4ed626c7..2b56410d 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -149,10 +149,15 @@ class QUnFrameWindow(resizableframeless): def parsehira(self, text): hira = [] + try: if gobject.baseobject.hira_: - hira = gobject.baseobject.hira_.parseparse(text) + for i, _ in enumerate(text.split("\n")): + h = gobject.baseobject.hira_.parseparse(_) + if i: + hira += [{"orig": "\n", "hira": "\n"}] + hira += h except: print_exc() return hira @@ -171,12 +176,7 @@ class QUnFrameWindow(resizableframeless): return text = self.cleartext(text) if hira: - hiras = [self.parsehira(_) for _ in text.split("\n")] - hira = [] - for i, _h in enumerate(hiras): - if i: - hira += [{"orig": "\n", "hira": "\n"}] - hira += _h + hira = self.parsehira(text) else: hira = [] self.translate_text.setnextfont(origin) diff --git a/LunaTranslator/files/anki/back.html b/LunaTranslator/files/anki/back.html index b6baef2a..d69d42c9 100644 --- a/LunaTranslator/files/anki/back.html +++ b/LunaTranslator/files/anki/back.html @@ -12,7 +12,11 @@ html = '' if (ruby.length) { for (i = 0; i < ruby.length; i++) { - html += ruby[i]['orig'] + '' + ruby[i]['hira'] + ''; + html += ruby[i]['orig']; + if (ruby[i]['orig'] != ruby[i]['hira']) + html += '' + ruby[i]['hira'] + ''; + else + html += ''; } html = '' + html + '' document.getElementById('rubyword').innerHTML = html @@ -24,7 +28,7 @@ -
+
{{example_sentence}}
diff --git a/LunaTranslator/files/anki/front.html b/LunaTranslator/files/anki/front.html index ce417f14..e540631a 100644 --- a/LunaTranslator/files/anki/front.html +++ b/LunaTranslator/files/anki/front.html @@ -12,7 +12,11 @@ html = '' if (ruby.length) { for (i = 0; i < ruby.length; i++) { - html += ruby[i]['orig'] + '' + ruby[i]['hira'] + ''; + html += ruby[i]['orig']; + if (ruby[i]['orig'] != ruby[i]['hira']) + html += '' + ruby[i]['hira'] + ''; + else + html += ''; } html = '' + html + '' document.getElementById('rubyword').innerHTML = html @@ -24,7 +28,7 @@ -
+
{{example_sentence}}
diff --git a/LunaTranslator/files/anki/style.css b/LunaTranslator/files/anki/style.css index 1af65e9c..ede2f7bd 100644 --- a/LunaTranslator/files/anki/style.css +++ b/LunaTranslator/files/anki/style.css @@ -17,6 +17,7 @@ } .example-div { + text-align: center; font-family: BIZ UDGothic; font-size: 24px; text-align: center; diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index 06419e98..cc1b9aa5 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -194,7 +194,8 @@ "keycode": 120 } }, - "autocrop": false + "autocrop": false, + "boldword": false }, "imageformat": -1, "ankiwindow": [ diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index 9f730c24..7a0d4142 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -798,5 +798,7 @@ "对齐": "محاذاة", "居左": "البقاء على اليسار", "居右": "يعيش الحق", - "截图保存格式": "حفظ الشكل" + "截图保存格式": "حفظ الشكل", + "交流群": "مجموعة ميلان", + "例句中加粗单词": "على سبيل المثال كلمة جريئة" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index ad1451e0..e3027fbf 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -798,5 +798,7 @@ "对齐": "對齊", "居左": "居左", "居右": "居右", - "截图保存格式": "截圖保存格式" + "截图保存格式": "截圖保存格式", + "交流群": "交流群", + "例句中加粗单词": "例句中加粗單詞" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index a5d18d75..510f591d 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -798,5 +798,7 @@ "对齐": "alignment", "居左": "be at the left side", "居右": "be at the right", - "截图保存格式": "Screenshot Save Format" + "截图保存格式": "Screenshot Save Format", + "交流群": "Communication groups", + "例句中加粗单词": "Bold words in the example sentence" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index 6c49ab42..7e56e333 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -798,5 +798,7 @@ "对齐": "Alinear", "居左": "Ju Zuo", "居右": "A la derecha", - "截图保存格式": "Formato de Guardar captura de pantalla" + "截图保存格式": "Formato de Guardar captura de pantalla", + "交流群": "Grupo de comunicación", + "例句中加粗单词": "Palabras en negrita en oraciones de ejemplo" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index 42e77a1c..e4b0e72d 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -798,5 +798,7 @@ "对齐": "Alignement", "居左": "Vivre à gauche", "居右": "Vivre à droite", - "截图保存格式": "Format de sauvegarde des captures d'écran" + "截图保存格式": "Format de sauvegarde des captures d'écran", + "交流群": "Groupe d'échange", + "例句中加粗单词": "Mots épaissis dans une phrase d'exemple" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 99acf835..e893ee78 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -798,5 +798,7 @@ "对齐": "allineamento", "居左": "essere sul lato sinistro", "居右": "essere a destra", - "截图保存格式": "Schermata Salva formato" + "截图保存格式": "Schermata Salva formato", + "交流群": "Gruppi di comunicazione", + "例句中加粗单词": "Parole grasse nella frase di esempio" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index 1cfcb706..b6e5d18e 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -798,5 +798,7 @@ "对齐": "配置", "居左": "左に位置する", "居右": "右に位置する", - "截图保存格式": "スクリーンショット保存形式" + "截图保存格式": "スクリーンショット保存形式", + "交流群": "こうりゅうぐん", + "例句中加粗单词": "例文中の太字単語" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index 4bca7a37..d9676ace 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -798,5 +798,7 @@ "对齐": "정렬", "居左": "왼쪽", "居右": "오른쪽", - "截图保存格式": "캡처 저장 형식" + "截图保存格式": "캡처 저장 형식", + "交流群": "교류군", + "例句中加粗单词": "예문에 단어를 굵게 넣다" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index 0e52bd18..8bcf010b 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -798,5 +798,7 @@ "对齐": "wyrównanie", "居左": "być po lewej stronie", "居右": "bądź po prawej stronie", - "截图保存格式": "Zrzut ekranu Zapisz format" + "截图保存格式": "Zrzut ekranu Zapisz format", + "交流群": "Grupy ds. komunikacji", + "例句中加粗单词": "Pogrubione słowa w zdaniu przykładowym" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index c775896b..6a7730b0 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -798,5 +798,7 @@ "对齐": "Выровнять", "居左": "Цзяо", "居右": "справа от дома", - "截图保存格式": "Формат сохранения снимков" + "截图保存格式": "Формат сохранения снимков", + "交流群": "Коммутаторная группа", + "例句中加粗单词": "Добавить слово в пример" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index d5c5d5bc..dc734d81 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -798,5 +798,7 @@ "对齐": "จัดตำแหน่ง", "居左": "จู", "居右": "จูขวา", - "截图保存格式": "รูปแบบการบันทึกภาพหน้าจอ" + "截图保存格式": "รูปแบบการบันทึกภาพหน้าจอ", + "交流群": "กลุ่มสื่อสาร", + "例句中加粗单词": "คำหยาบในประโยคตัวอย่าง" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index fa57b8f6..3aee48a5 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -798,5 +798,7 @@ "对齐": "yönlendirme", "居左": "sol tarafta", "居右": "Sağda ol.", - "截图保存格式": "Ekran Görüntüsü Kaydet Format" + "截图保存格式": "Ekran Görüntüsü Kaydet Format", + "交流群": "İletişim grupları", + "例句中加粗单词": "Örneğin cümlelerinde kalın kelimeler" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 3ae415dd..49d27d4c 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -798,5 +798,7 @@ "对齐": "вирівнювання", "居左": "бути ліворуч,", "居右": "бути праворуч", - "截图保存格式": "Формат збереження знімка екрана" + "截图保存格式": "Формат збереження знімка екрана", + "交流群": "Групи комунікації", + "例句中加粗单词": "Жирі слова у прикладному реченні" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index f4052164..0a607dcf 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -798,5 +798,7 @@ "对齐": "Canh lề", "居左": "Trái", "居右": "Bên phải", - "截图保存格式": "Định dạng lưu ảnh chụp màn hình" + "截图保存格式": "Định dạng lưu ảnh chụp màn hình", + "交流群": "Nhóm trao đổi", + "例句中加粗单词": "Từ in đậm trong câu ví dụ" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 3f5907cf..51b575b3 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -799,5 +799,6 @@ "居左": "", "居右": "", "截图保存格式": "", - "交流群": "" + "交流群": "", + "例句中加粗单词": "" } \ No newline at end of file