H5W3
当前位置:H5W3 > python > 正文

python谷歌翻译API接口googletrans使用

谷歌翻译API-python接口-Googletrans-云海天教程

  • 快速可靠 – 它使用translate.google.com使用的相同服务器
  • 自动语言检测
  • 批量翻译
  • 可自定义的服务URL
  • 连接池(使用requests.Session的优点)
  • HTTP / 2支持

pip install googletrans

基本用法

1.翻译成中文

from googletrans import Translator
translator = Translator()
print(translator.translate("Sunday", dest="zh-CN").text)

2 批量翻译

from googletrans import Translator
translator = Translator()
translations = translator.translate(["The quick brown fox", "jumps over", "the lazy dog"], dest="ko")
for translation in translations:
print(translation.origin, " -> ", translation.text)

下面是支持的语言

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”,
“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”
}

本文地址:H5W3 » python谷歌翻译API接口googletrans使用