Created
March 3, 2022 08:18
-
-
Save jjsantanna/2dbb791767685a4ca2dbfd08b34c5696 to your computer and use it in GitHub Desktop.
Google translation paid api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ATTENTION: PAID solution from Google | |
# https://cloud.google.com/translate/docs/setup | |
# https://cloud.google.com/translate/docs/basic/quickstart | |
import os | |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="BLABLABLA.json" | |
def translate_text(target, text): | |
import six | |
from google.cloud import translate_v2 as translate | |
translate_client = translate.Client() | |
if isinstance(text, six.binary_type): | |
text = text.decode("utf-8") | |
result = translate_client.translate(text, target_language=target) | |
return result | |
# result['translatedText'], result['detectedSourceLanguage'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment