From df15c21b356c7d3a46bd485e7d158d9377bd7fc1 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 14 Jun 2024 14:05:41 +0200 Subject: [PATCH] [feat] mozhi: fix crash, support synonyms and definition --- searx/engines/mozhi.py | 12 +++++++++--- 1 file 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"
{word['word']}
" + infobox += f"
{word['word']}: {word['definition']}
" - for example in word['examples_target']: - infobox += f"
{re.sub(r'<|>', '', example)}
" + if word['examples_target']: + for example in word['examples_target']: + infobox += f"
{re.sub(r'<|>', '', example)}
" + infobox += f"
{re.sub(r'<|>', '', example)}
" infobox += "
" + if translation['source_synonyms']: + infobox += f"
{gettext('Synonyms')}: {', '.join(translation['source_synonyms'])}
" + result = { 'infobox': translation['translated-text'], 'content': infobox,