summaryrefslogtreecommitdiff
path: root/searx/engines/translated.py
blob: 9900c017bf3edbe0b50ef113409e44bc6f9750b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
 MyMemory Translated
"""

# about
about = {
    "website": 'https://mymemory.translated.net/',
    "wikidata_id": None,
    "official_api_documentation": 'https://mymemory.translated.net/doc/spec.php',
    "use_official_api": True,
    "require_api_key": False,
    "results": 'JSON',
}

engine_type = 'online_dictionary'
categories = ['dictionaries']
url = 'https://api.mymemory.translated.net/get?q={query}&langpair={from_lang}|{to_lang}{key}'
web_url = 'https://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}'
weight = 100
https_support = True

api_key = ''


def request(query, params):
    if api_key:
        key_form = '&key=' + api_key
    else:
        key_form = ''
    params['url'] = url.format(
        from_lang=params['from_lang'][1], to_lang=params['to_lang'][1], query=params['query'], key=key_form
    )
    return params


def response(resp):
    results = []
    results.append(
        {
            'url': web_url.format(
                from_lang=resp.search_params['from_lang'][2],
                to_lang=resp.search_params['to_lang'][2],
                query=resp.search_params['query'],
            ),
            'title': '[{0}-{1}] {2}'.format(
                resp.search_params['from_lang'][1], resp.search_params['to_lang'][1], resp.search_params['query']
            ),
            'content': resp.json()['responseData']['translatedText'],
        }
    )
    return results