2021-01-13 10:31:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-09-06 14:36:04 +00:00
|
|
|
"""
|
|
|
|
MyMemory Translated
|
|
|
|
"""
|
2016-09-06 13:40:07 +00:00
|
|
|
|
2021-01-13 10:31:25 +00:00
|
|
|
# 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',
|
|
|
|
}
|
|
|
|
|
2021-06-03 16:02:47 +00:00
|
|
|
engine_type = 'online_dictionary'
|
2021-12-28 15:26:38 +00:00
|
|
|
categories = ['dictionaries']
|
2020-08-06 15:42:46 +00:00
|
|
|
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}'
|
2016-09-06 13:40:07 +00:00
|
|
|
weight = 100
|
2020-12-09 16:33:18 +00:00
|
|
|
https_support = True
|
2016-09-06 13:40:07 +00:00
|
|
|
|
2016-09-06 14:12:34 +00:00
|
|
|
api_key = ''
|
2016-09-06 13:40:07 +00:00
|
|
|
|
2016-09-06 13:44:05 +00:00
|
|
|
|
2016-09-06 13:40:07 +00:00
|
|
|
def request(query, params):
|
2016-09-06 14:12:34 +00:00
|
|
|
if api_key:
|
|
|
|
key_form = '&key=' + api_key
|
|
|
|
else:
|
|
|
|
key_form = ''
|
2021-12-27 08:26:22 +00:00
|
|
|
params['url'] = url.format(
|
|
|
|
from_lang=params['from_lang'][1], to_lang=params['to_lang'][1], query=params['query'], key=key_form
|
|
|
|
)
|
2016-09-06 13:40:07 +00:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
2021-12-27 08:26:22 +00:00
|
|
|
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'],
|
|
|
|
}
|
|
|
|
)
|
2016-09-06 13:40:07 +00:00
|
|
|
return results
|