2021-11-29 19:28:30 +00:00
|
|
|
import requests
|
2021-02-02 21:05:09 +00:00
|
|
|
|
|
|
|
BASE_URLS = {
|
|
|
|
"GOOGLE_TRANSLATE": "https://translate.google.com/m",
|
|
|
|
"PONS": "https://en.pons.com/translate/",
|
|
|
|
"YANDEX": "https://translate.yandex.net/api/{version}/tr.json/{endpoint}",
|
|
|
|
"LINGUEE": "https://www.linguee.com/",
|
|
|
|
"MYMEMORY": "http://api.mymemory.translated.net/get",
|
|
|
|
"QCRI": "https://mt.qcri.org/api/v1/{endpoint}?",
|
2021-11-29 19:28:30 +00:00
|
|
|
"DEEPL": "https://api.deepl.com/{version}/",
|
|
|
|
"DEEPL_FREE": "https://api-free.deepl.com/v2/",
|
|
|
|
"MICROSOFT_TRANSLATE": "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0",
|
|
|
|
"PAPAGO": "https://papago.naver.com/",
|
|
|
|
"PAPAGO_API": "https://openapi.naver.com/v1/papago/n2mt"
|
2021-02-02 21:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GOOGLE_CODES_TO_LANGUAGES = {
|
|
|
|
'af': 'afrikaans',
|
|
|
|
'sq': 'albanian',
|
|
|
|
'am': 'amharic',
|
|
|
|
'ar': 'arabic',
|
|
|
|
'hy': 'armenian',
|
|
|
|
'az': 'azerbaijani',
|
|
|
|
'eu': 'basque',
|
|
|
|
'be': 'belarusian',
|
|
|
|
'bn': 'bengali',
|
|
|
|
'bs': 'bosnian',
|
|
|
|
'bg': 'bulgarian',
|
|
|
|
'ca': 'catalan',
|
|
|
|
'ceb': 'cebuano',
|
|
|
|
'ny': 'chichewa',
|
2021-11-29 19:28:30 +00:00
|
|
|
'zh': 'chinese',
|
2021-02-02 21:05:09 +00:00
|
|
|
'zh-cn': 'chinese (simplified)',
|
|
|
|
'zh-tw': 'chinese (traditional)',
|
|
|
|
'co': 'corsican',
|
|
|
|
'hr': 'croatian',
|
|
|
|
'cs': 'czech',
|
|
|
|
'da': 'danish',
|
|
|
|
'nl': 'dutch',
|
|
|
|
'en': 'english',
|
|
|
|
'eo': 'esperanto',
|
|
|
|
'et': 'estonian',
|
|
|
|
'tl': 'filipino',
|
|
|
|
'fi': 'finnish',
|
|
|
|
'fr': 'french',
|
|
|
|
'fy': 'frisian',
|
|
|
|
'gl': 'galician',
|
|
|
|
'ka': 'georgian',
|
|
|
|
'de': 'german',
|
|
|
|
'el': 'greek',
|
|
|
|
'gu': 'gujarati',
|
|
|
|
'ht': 'haitian creole',
|
|
|
|
'ha': 'hausa',
|
|
|
|
'haw': 'hawaiian',
|
|
|
|
'iw': 'hebrew',
|
|
|
|
'hi': 'hindi',
|
|
|
|
'hmn': 'hmong',
|
|
|
|
'hu': 'hungarian',
|
|
|
|
'is': 'icelandic',
|
|
|
|
'ig': 'igbo',
|
|
|
|
'id': 'indonesian',
|
|
|
|
'ga': 'irish',
|
|
|
|
'it': 'italian',
|
|
|
|
'ja': 'japanese',
|
|
|
|
'jw': 'javanese',
|
|
|
|
'kn': 'kannada',
|
|
|
|
'kk': 'kazakh',
|
|
|
|
'km': 'khmer',
|
|
|
|
'ko': 'korean',
|
|
|
|
'ku': 'kurdish (kurmanji)',
|
|
|
|
'ky': 'kyrgyz',
|
|
|
|
'lo': 'lao',
|
|
|
|
'la': 'latin',
|
|
|
|
'lv': 'latvian',
|
|
|
|
'lt': 'lithuanian',
|
|
|
|
'lb': 'luxembourgish',
|
|
|
|
'mk': 'macedonian',
|
|
|
|
'mg': 'malagasy',
|
|
|
|
'ms': 'malay',
|
|
|
|
'ml': 'malayalam',
|
|
|
|
'mt': 'maltese',
|
|
|
|
'mi': 'maori',
|
|
|
|
'mr': 'marathi',
|
|
|
|
'mn': 'mongolian',
|
|
|
|
'my': 'myanmar (burmese)',
|
|
|
|
'ne': 'nepali',
|
|
|
|
'no': 'norwegian',
|
|
|
|
'ps': 'pashto',
|
|
|
|
'fa': 'persian',
|
|
|
|
'pl': 'polish',
|
|
|
|
'pt': 'portuguese',
|
|
|
|
'pa': 'punjabi',
|
|
|
|
'ro': 'romanian',
|
|
|
|
'ru': 'russian',
|
|
|
|
'sm': 'samoan',
|
|
|
|
'gd': 'scots gaelic',
|
|
|
|
'sr': 'serbian',
|
|
|
|
'st': 'sesotho',
|
|
|
|
'sn': 'shona',
|
|
|
|
'sd': 'sindhi',
|
|
|
|
'si': 'sinhala',
|
|
|
|
'sk': 'slovak',
|
|
|
|
'sl': 'slovenian',
|
|
|
|
'so': 'somali',
|
|
|
|
'es': 'spanish',
|
|
|
|
'su': 'sundanese',
|
|
|
|
'sw': 'swahili',
|
|
|
|
'sv': 'swedish',
|
|
|
|
'tg': 'tajik',
|
|
|
|
'ta': 'tamil',
|
|
|
|
'te': 'telugu',
|
|
|
|
'th': 'thai',
|
|
|
|
'tr': 'turkish',
|
|
|
|
'uk': 'ukrainian',
|
|
|
|
'ur': 'urdu',
|
|
|
|
'uz': 'uzbek',
|
|
|
|
'vi': 'vietnamese',
|
|
|
|
'cy': 'welsh',
|
|
|
|
'xh': 'xhosa',
|
|
|
|
'yi': 'yiddish',
|
|
|
|
'yo': 'yoruba',
|
|
|
|
'zu': 'zulu',
|
|
|
|
'fil': 'Filipino',
|
|
|
|
'he': 'Hebrew'
|
|
|
|
}
|
|
|
|
|
|
|
|
GOOGLE_LANGUAGES_TO_CODES = {v: k for k, v in GOOGLE_CODES_TO_LANGUAGES.items()}
|
|
|
|
|
|
|
|
PONS_CODES_TO_LANGUAGES = {
|
|
|
|
'ar': 'arabic',
|
|
|
|
'bg': 'bulgarian',
|
|
|
|
'zh-cn': 'chinese',
|
|
|
|
'cs': 'czech',
|
|
|
|
'da': 'danish',
|
|
|
|
'nl': 'dutch',
|
|
|
|
'en': 'english',
|
|
|
|
'fr': 'french',
|
|
|
|
'de': 'german',
|
|
|
|
'el': 'greek',
|
|
|
|
'hu': 'hungarian',
|
|
|
|
'it': 'italian',
|
|
|
|
'la': 'latin',
|
|
|
|
'no': 'norwegian',
|
|
|
|
'pl': 'polish',
|
|
|
|
'pt': 'portuguese',
|
|
|
|
'ru': 'russian',
|
|
|
|
'sl': 'slovenian',
|
|
|
|
'es': 'spanish',
|
|
|
|
'sv': 'swedish',
|
|
|
|
'tr': 'turkish',
|
|
|
|
'elv': 'elvish'
|
|
|
|
}
|
|
|
|
|
|
|
|
PONS_LANGUAGES_TO_CODES = {v: k for k, v in PONS_CODES_TO_LANGUAGES.items()}
|
|
|
|
|
|
|
|
LINGUEE_LANGUAGES_TO_CODES = {
|
|
|
|
"maltese": "mt",
|
|
|
|
"english": "en",
|
|
|
|
"german": "de",
|
|
|
|
"bulgarian": "bg",
|
|
|
|
"polish": "pl",
|
|
|
|
"portuguese": "pt",
|
|
|
|
"hungarian": "hu",
|
|
|
|
"romanian": "ro",
|
|
|
|
"russian": "ru",
|
2021-11-29 19:28:30 +00:00
|
|
|
# "serbian": "sr",
|
2021-02-02 21:05:09 +00:00
|
|
|
"dutch": "nl",
|
|
|
|
"slovakian": "sk",
|
|
|
|
"greek": "el",
|
|
|
|
"slovenian": "sl",
|
|
|
|
"danish": "da",
|
|
|
|
"italian": "it",
|
|
|
|
"spanish": "es",
|
|
|
|
"finnish": "fi",
|
|
|
|
"chinese": "zh",
|
|
|
|
"french": "fr",
|
2021-11-29 19:28:30 +00:00
|
|
|
# "croatian": "hr",
|
2021-02-02 21:05:09 +00:00
|
|
|
"czech": "cs",
|
|
|
|
"laotian": "lo",
|
|
|
|
"swedish": "sv",
|
|
|
|
"latvian": "lv",
|
|
|
|
"estonian": "et",
|
|
|
|
"japanese": "ja"
|
|
|
|
}
|
|
|
|
|
|
|
|
LINGUEE_CODE_TO_LANGUAGE = {v: k for k, v in LINGUEE_LANGUAGES_TO_CODES.items()}
|
|
|
|
|
|
|
|
# "72e9e2cc7c992db4dcbdd6fb9f91a0d1"
|
2021-11-29 19:28:30 +00:00
|
|
|
|
|
|
|
# obtaining the current list of supported Microsoft languages for translation
|
|
|
|
|
|
|
|
microsoft_languages_api_url = "https://api.cognitive.microsofttranslator.com/languages?api-version=3.0&scope=translation"
|
|
|
|
microsoft_languages_response = requests.get(microsoft_languages_api_url)
|
|
|
|
translation_dict = microsoft_languages_response.json()['translation']
|
|
|
|
|
|
|
|
MICROSOFT_CODES_TO_LANGUAGES = {translation_dict[k]['name'].lower(): k for k in translation_dict.keys()}
|
|
|
|
|
|
|
|
DEEPL_LANGUAGE_TO_CODE = {
|
|
|
|
"bulgarian": "bg",
|
|
|
|
"czech": "cs",
|
|
|
|
"danish": "da",
|
|
|
|
"german": "de",
|
|
|
|
"greek": "el",
|
|
|
|
"english": "en",
|
|
|
|
"spanish": "es",
|
|
|
|
"estonian": "et",
|
|
|
|
"finnish": "fi",
|
|
|
|
"french": "fr",
|
|
|
|
"hungarian": "hu",
|
|
|
|
"italian": "it",
|
|
|
|
"japanese": "ja",
|
|
|
|
"lithuanian": "lt",
|
|
|
|
"latvian": "lv",
|
|
|
|
"dutch": "nl",
|
|
|
|
"polish": "pl",
|
|
|
|
"portuguese": "pt",
|
|
|
|
"romanian": "ro",
|
|
|
|
"russian": "ru",
|
|
|
|
"slovak": "sk",
|
|
|
|
"slovenian": "sl",
|
|
|
|
"swedish": "sv",
|
|
|
|
"chinese": "zh"
|
|
|
|
}
|
|
|
|
|
|
|
|
DEEPL_CODE_TO_LANGUAGE = {v: k for k, v in DEEPL_LANGUAGE_TO_CODE.items()}
|
|
|
|
|
|
|
|
PAPAGO_CODE_TO_LANGUAGE = {
|
|
|
|
'ko': 'Korean',
|
|
|
|
'en': 'English',
|
|
|
|
'ja': 'Japanese',
|
|
|
|
'zh-CN': 'Chinese',
|
|
|
|
'zh-TW': 'Chinese traditional',
|
|
|
|
'es': 'Spanish',
|
|
|
|
'fr': 'French',
|
|
|
|
'vi': 'Vietnamese',
|
|
|
|
'th': 'Thai',
|
|
|
|
'id': 'Indonesia'
|
|
|
|
}
|
|
|
|
|
|
|
|
PAPAGO_LANGUAGE_TO_CODE = {v: k for v, k in PAPAGO_CODE_TO_LANGUAGE.items()}
|
|
|
|
|
|
|
|
QCRI_CODE_TO_LANGUAGE = {
|
|
|
|
'ar': 'Arabic',
|
|
|
|
'en': 'English',
|
|
|
|
'es': 'Spanish'
|
|
|
|
}
|
|
|
|
|
|
|
|
QCRI_LANGUAGE_TO_CODE = {
|
|
|
|
v: k for k, v in QCRI_CODE_TO_LANGUAGE.items()
|
|
|
|
}
|