Using Google Translator api to convert text in python.

krishankant singhal
2 min readAug 7, 2023

Step 1: Sign Up for Google Cloud Translation API

  1. Go to Google Cloud Console.
  2. Create a new project or select an existing project.
  3. Enable the “Cloud Translation API” for your project.
  4. Create credentials: Choose “Service Account Key,” select “JSON” format, and download the credentials JSON file.

Step 2: Install Required Libraries

First, make sure you have Streamlit and the googletrans library installed. You can install them using the following commands:

pip install streamlit googletrans==4.0.0-rc1

Step 3: Create the Translation App

Create a Python script named translation_app.py and follow the steps below:

import streamlit as st
from googletrans import Translator
def translate_text(text, source_lang, target_lang):
translator = Translator()
translated_text = translator.translate(text, src=source_lang, dest=target_lang)
return translated_text.text
def main():
st.title("Multilingual Text Translation App")
# Load Google API credentials
credentials_path = "YOUR_GOOGLE_CREDENTIALS_JSON_FILE.json" os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_path

--

--

krishankant singhal

Angular,Vuejs,Android,Java,Git developer. i am nerd who want to learn new technologies, goes in depth.