excel_translator/utils/helpers.py
2025-04-06 21:39:00 +02:00

31 lines
1.1 KiB
Python

from typing import Any, Dict
import os
import logging
def setup_logging() -> None:
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def save_translated_file(file_path: str, data: Any) -> str:
base, ext = os.path.splitext(file_path)
translated_file_path = f"{base}_translated{ext}"
# Assuming data is a DataFrame or similar structure
data.to_excel(translated_file_path, index=False)
logging.info(f"Translated file saved as: {translated_file_path}")
return translated_file_path
def read_excel_file(file_path: str) -> Dict[str, Any]:
import pandas as pd
logging.info(f"Reading Excel file: {file_path}")
return pd.read_excel(file_path, sheet_name=None)
def translate_text(text: str, target_language: str) -> str:
# Placeholder for translation logic
logging.info(f"Translating text: {text} to {target_language}")
return text # Replace with actual translation logic
def handle_file_not_found(file_path: str) -> None:
logging.error(f"File not found: {file_path}")
raise FileNotFoundError(f"The file {file_path} does not exist.")