summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-06-14 14:05:41 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-06-15 11:33:09 +0200
commitdf15c21b356c7d3a46bd485e7d158d9377bd7fc1 (patch)
treebabaa47f232c1618d1f4b2844a2f7b34e001f236
parent1fe13d0ba4dea086654b30746fa3cc8f2645606f (diff)
downloadsearxng-df15c21b356c7d3a46bd485e7d158d9377bd7fc1.tar.gz
searxng-df15c21b356c7d3a46bd485e7d158d9377bd7fc1.zip
[feat] mozhi: fix crash, support synonyms and definition
-rw-r--r--searx/engines/mozhi.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/searx/engines/mozhi.py b/searx/engines/mozhi.py
index 3858ca4ef..63c90084e 100644
--- a/searx/engines/mozhi.py
+++ b/searx/engines/mozhi.py
@@ -4,6 +4,7 @@
import random
import re
from urllib.parse import urlencode
+from flask_babel import gettext
about = {
"website": 'https://codeberg.org/aryak/mozhi',
@@ -43,13 +44,18 @@ def response(resp):
if translation['word_choices']:
for word in translation['word_choices']:
- infobox += f"<dl><dt>{word['word']}</dt>"
+ infobox += f"<dl><dt>{word['word']}: {word['definition']}</dt>"
- for example in word['examples_target']:
- infobox += f"<dd>{re.sub(r'<|>', '', example)}</dd>"
+ if word['examples_target']:
+ for example in word['examples_target']:
+ infobox += f"<dd>{re.sub(r'<|>', '', example)}</dd>"
+ infobox += f"<dd>{re.sub(r'<|>', '', example)}</dd>"
infobox += "</dl>"
+ if translation['source_synonyms']:
+ infobox += f"<dl><dt>{gettext('Synonyms')}: {', '.join(translation['source_synonyms'])}</dt></dl>"
+
result = {
'infobox': translation['translated-text'],
'content': infobox,