Skip to content

Instantly share code, notes, and snippets.

@jjsantanna
Created March 3, 2022 08:18
Show Gist options
  • Save jjsantanna/2dbb791767685a4ca2dbfd08b34c5696 to your computer and use it in GitHub Desktop.
Save jjsantanna/2dbb791767685a4ca2dbfd08b34c5696 to your computer and use it in GitHub Desktop.
Google translation paid api
# 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