google transalte from one language to another language , need language expert. since it is sensitive information
https://cloud.google.com/translate/docs/languages
#version 2
import os
from google.cloud import translate_v2 as translate
# Constants
GOOGLE_CREDENTIALS_FILE = "/content/credentials.json" # Path to your Google API credentials JSON file
SOURCE_FILE = "/content/CLOUD_నాస్తికులు - ఆస్తికులు_12sep204.txt" # Path to the source text file
TARGET_FILE = "/content/translated_Lang.txt" # Path to save the translated text file
SOURCE_LANGUAGE = "te" # Source language code (e.g., 'en' for English)
TARGET_LANGUAGE = "hi" # Target language code (e.g., 'fr' for French)
CHUNK_SIZE = 4000 # Maximum chunk size to avoid exceeding API limits
# Function to set up Google Translate API client
def setup_translate_client():
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = GOOGLE_CREDENTIALS_FILE
return translate.Client()
# Function to translate text
def translate_text(client, text, source_lang, target_lang):
result = client.translate(text, source_language=source_lang, target_language=target_lang)
return result['translatedText']
# Function to read text from file (with line breaks preserved)
def read_text_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
return file.readlines() # This will return a list of lines, preserving line breaks
# Function to write text to file (preserve line breaks)
def write_text_file(file_path, content):
with open(file_path, 'w', encoding='utf-8') as file:
file.write(content) # Content will be written with line breaks
# Function to split text into chunks while preserving line breaks
def chunk_text(lines, chunk_size):
chunks = []
current_chunk = ""
for line in lines:
# If adding this line exceeds chunk size, save the current chunk and start a new one
if len(current_chunk) + len(line) > chunk_size:
chunks.append(current_chunk)
current_chunk = line
else:
current_chunk += line
# Add the last chunk if there is any leftover content
if current_chunk:
chunks.append(current_chunk)
return chunks
# Main function to translate large text file
def translate_large_text_file():
# Check if the Google credentials file exists
if not os.path.exists(GOOGLE_CREDENTIALS_FILE):
print(f"Error: The Google API credentials file {GOOGLE_CREDENTIALS_FILE} does not exist.")
return
# Check if the source file exists
if not os.path.exists(SOURCE_FILE):
print(f"Error: The source file {SOURCE_FILE} does not exist.")
return
# Read the content of the source file (preserving line breaks)
lines_to_translate = read_text_file(SOURCE_FILE)
# Initialize Google Translate client
translate_client = setup_translate_client()
# Split text into chunks
chunks = chunk_text(lines_to_translate, CHUNK_SIZE)
# Translate each chunk and append to the output
translated_text = ""
for idx, chunk in enumerate(chunks, 1):
print(f"Translating chunk {idx}/{len(chunks)}...")
translated_text += translate_text(translate_client, chunk, SOURCE_LANGUAGE, TARGET_LANGUAGE)
# Save the translated text to a file
write_text_file(TARGET_FILE, translated_text)
print(f"Translation completed!")
print(f"Translated text file saved at: {TARGET_FILE}")
# Call the main function
translate_large_text_file()
# got line spaces, but , language expert is needed , it has sensitive information ,
#example నాస్తికుడు - విశ్వాసి.
#సంపద అంటే సంపద అని అందరికీ తెలుసు. స్థిరాస్తులు లేదా ఆస్తిని కలిగి ఉన్న వ్యక్తిని ఆస్తి యజమాని లేదా ఆస్తి యజమాని అంటారు. సంస్కృత భాషలో ' లేదు. అక్షరాల వాడకం ' 'కడు' అనే అర్థంలో చేస్తారు. గురువుకు గానీ, ఆస్తిక వాదానికి గానీ అర్థం చెప్పలేదు. నో + నాస్తికుడు అనే పదాలు కలిపితే నాస్తికుడు అవుతాడు. నాస్తికుడు అంటే ఆస్తి లేనివాడు అని అర్థం. నాస్తికుడు మరియు నాస్తికుడు అనే పదాలు నేడు ధనవంతులు మరియు ధనవంతులు కానివారిని సూచించడానికి
#actual
#నాస్తికులు - ఆస్తికులు.
#ఆస్తి అనగా సంపద అని అందరికి తెలుసు. స్థిరాస్థులుగాని, చరాస్తులుగాని కలవానిని ఆస్తిపరుడు లేక
#ఆస్తికుడు అంటున్నాము. సంస్కృత భాషలో 'కాడు' అను అర్థమునకు 'న' అను అక్షరమును చెప్పుచుందురు. ఆస్తిపరుడు
#కాడు అను అర్థమునకు న ఆస్తికుడు అనెడివారు. న+ఆస్తికుడు అను వాటిని కలిపిపలికితే నాస్తికుడు అగును.