.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.mozhi Namespace Reference

Functions

 request (_query, params)
 
 response (resp)
 

Variables

dict about
 
str engine_type = 'online_dictionary'
 
list categories = ['general', 'translate']
 
str base_url = "https://mozhi.aryak.me"
 
str mozhi_engine = "google"
 
str re_transliteration_unsupported = "Direction '.*' is not supported"
 

Detailed Description

Mozhi (alternative frontend for popular translation engines)

Function Documentation

◆ request()

searx.engines.mozhi.request ( _query,
params )

Definition at line 27 of file mozhi.py.

27def request(_query, params):
28 request_url = random.choice(base_url) if isinstance(base_url, list) else base_url
29
30 args = {'from': params['from_lang'][1], 'to': params['to_lang'][1], 'text': params['query'], 'engine': mozhi_engine}
31 params['url'] = f"{request_url}/api/translate?{urlencode(args)}"
32 return params
33
34

◆ response()

searx.engines.mozhi.response ( resp)

Definition at line 35 of file mozhi.py.

35def response(resp):
36 translation = resp.json()
37
38 infobox = ""
39
40 if translation['target_transliteration'] and not re.match(
41 re_transliteration_unsupported, translation['target_transliteration']
42 ):
43 infobox = f"<b>{translation['target_transliteration']}</b>"
44
45 if translation['word_choices']:
46 for word in translation['word_choices']:
47 infobox += f"<dl><dt>{word['word']}: {word['definition']}</dt>"
48
49 if word['examples_target']:
50 for example in word['examples_target']:
51 infobox += f"<dd>{re.sub(r'<|>', '', example)}</dd>"
52 infobox += f"<dd>{re.sub(r'<|>', '', example)}</dd>"
53
54 infobox += "</dl>"
55
56 if translation['source_synonyms']:
57 infobox += f"<dl><dt>{gettext('Synonyms')}: {', '.join(translation['source_synonyms'])}</dt></dl>"
58
59 result = {
60 'infobox': translation['translated-text'],
61 'content': infobox,
62 }
63
64 return [result]

Variable Documentation

◆ about

dict searx.engines.mozhi.about
Initial value:
1= {
2 "website": 'https://codeberg.org/aryak/mozhi',
3 "wikidata_id": None,
4 "official_api_documentation": 'https://mozhi.aryak.me/api/swagger/index.html',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 9 of file mozhi.py.

◆ base_url

str searx.engines.mozhi.base_url = "https://mozhi.aryak.me"

Definition at line 21 of file mozhi.py.

◆ categories

list searx.engines.mozhi.categories = ['general', 'translate']

Definition at line 19 of file mozhi.py.

◆ engine_type

str searx.engines.mozhi.engine_type = 'online_dictionary'

Definition at line 18 of file mozhi.py.

◆ mozhi_engine

str searx.engines.mozhi.mozhi_engine = "google"

Definition at line 22 of file mozhi.py.

◆ re_transliteration_unsupported

str searx.engines.mozhi.re_transliteration_unsupported = "Direction '.*' is not supported"

Definition at line 24 of file mozhi.py.