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'] + '';
+ html += ruby[i]['orig'];
+ if (ruby[i]['orig'] != ruby[i]['hira'])
+ html += '';
+ else
+ html += '';
}
html = '' + html + ''
document.getElementById('rubyword').innerHTML = html
@@ -24,7 +28,7 @@
-