.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
mozhi.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Mozhi (alternative frontend for popular translation engines)"""
3
4
import
random
5
import
re
6
from
urllib.parse
import
urlencode
7
8
about = {
9
"website"
:
'https://codeberg.org/aryak/mozhi'
,
10
"wikidata_id"
:
None
,
11
"official_api_documentation"
:
'https://mozhi.aryak.me/api/swagger/index.html'
,
12
"use_official_api"
:
True
,
13
"require_api_key"
:
False
,
14
"results"
:
'JSON'
,
15
}
16
17
engine_type =
'online_dictionary'
18
categories = [
'general'
,
'translate'
]
19
20
base_url =
"https://mozhi.aryak.me"
21
mozhi_engine =
"google"
22
23
re_transliteration_unsupported =
"Direction '.*' is not supported"
24
25
26
def
request
(_query, params):
27
request_url = random.choice(base_url)
if
isinstance(base_url, list)
else
base_url
28
29
args = {
'from'
: params[
'from_lang'
][1],
'to'
: params[
'to_lang'
][1],
'text'
: params[
'query'
],
'engine'
: mozhi_engine}
30
params[
'url'
] = f
"{request_url}/api/translate?{urlencode(args)}"
31
return
params
32
33
34
def
response
(resp):
35
translation = resp.json()
36
37
infobox =
""
38
39
if
translation[
'target_transliteration'
]
and
not
re.match(
40
re_transliteration_unsupported, translation[
'target_transliteration'
]
41
):
42
infobox = f
"<b>{translation['target_transliteration']}</b>"
43
44
if
translation[
'word_choices'
]:
45
for
word
in
translation[
'word_choices'
]:
46
infobox += f
"<dl><dt>{word['word']}</dt>"
47
48
for
example
in
word[
'examples_target'
]:
49
infobox += f
"<dd>{re.sub(r'<|>', '', example)}</dd>"
50
51
infobox +=
"</dl>"
52
53
result = {
54
'infobox'
: translation[
'translated-text'
],
55
'content'
: infobox,
56
}
57
58
return
[result]
searx.engines.mozhi.request
request(_query, params)
Definition
mozhi.py:26
searx.engines.mozhi.response
response(resp)
Definition
mozhi.py:34
searxng
searx
engines
mozhi.py
Generated on Wed May 15 2024 21:10:12 for .oO SearXNG Developer Documentation Oo. by
1.10.0