# Authenticate using credentials.
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "translate.json"
PROJECT_ID = "project-id"
LOCATION = "global"
# Imports the Google Cloud Translation library
from google.cloud import translate_v3
# Transliteration.
def romanize_text(text, src_lang="hi", tgt_lang="en"):
client = translate_v3.TranslationServiceClient()
parent = f"projects/{PROJECT_ID}/locations/{LOCATION}"
response = client.romanize_text(
request={
"parent": parent,
"contents": [text],
"source_language_code": src_lang,
"target_language_code": tgt_lang,
}
)
# Display the romanized for each input text provided
for romanization in response.romanizations:
print(f"Romanized text: {romanization.romanized_text}")
romanize_text('यज्ञ का अंतिम लक्ष्य क्या है')