fix: use Google Cloud API key for classic mode + translation verification
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2s
Two critical fixes: 1. Provider "google" (default classic mode) now checks for a Google Cloud API key (GOOGLE_CLOUD_API_KEY in env or admin settings). If present, uses GoogleCloudTranslationProvider (official API). Previously it always fell through to deep_translator (free scraper) which gets blocked in production, silently returning untranslated text. 2. Added translation verification: each translator now tracks how many texts were attempted vs actually changed. If 0 texts were translated, the job is marked as FAILED with a clear error message instead of returning the original file as "completed". Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -107,6 +107,7 @@ class ExcelTranslator:
|
||||
self._provider = provider
|
||||
self.formula_pattern = re.compile(r"=.*")
|
||||
self._custom_prompt: Optional[str] = None
|
||||
self._translation_stats = {"attempted": 0, "changed": 0}
|
||||
|
||||
def set_provider(self, provider: TranslationProvider) -> None:
|
||||
"""Set the translation provider."""
|
||||
@@ -387,26 +388,26 @@ class ExcelTranslator:
|
||||
def _batch_translate(
|
||||
self, texts: List[str], target_language: str, source_language: str = "auto"
|
||||
) -> List[str]:
|
||||
"""
|
||||
Batch translate using new provider interface.
|
||||
|
||||
Args:
|
||||
texts: List of texts to translate
|
||||
target_language: Target language code
|
||||
source_language: Source language code
|
||||
|
||||
Returns:
|
||||
List of translated texts (same order as input)
|
||||
"""
|
||||
if not texts:
|
||||
return []
|
||||
|
||||
non_empty = [t for t in texts if t and t.strip()]
|
||||
self._translation_stats["attempted"] += len(non_empty)
|
||||
|
||||
if self._provider is not None:
|
||||
return self._translate_with_provider(
|
||||
translated = self._translate_with_provider(
|
||||
texts, target_language, source_language
|
||||
)
|
||||
else:
|
||||
translated = self._translate_with_legacy(texts, target_language, source_language)
|
||||
|
||||
return self._translate_with_legacy(texts, target_language, source_language)
|
||||
changed = sum(1 for orig, trans in zip(texts, translated) if orig != trans and trans.strip())
|
||||
self._translation_stats["changed"] += changed
|
||||
|
||||
return translated
|
||||
|
||||
def get_translation_stats(self) -> dict:
|
||||
return dict(self._translation_stats)
|
||||
|
||||
def _translate_with_provider(
|
||||
self, texts: List[str], target_language: str, source_language: str
|
||||
|
||||
Reference in New Issue
Block a user