|
|
@@ -64,16 +64,19 @@ def process_row(row, search_term_index):
|
|
|
# Add translation column after search term
|
|
|
search_term = row[search_term_index]
|
|
|
logger.info(f"Translating: {search_term}")
|
|
|
- translations = translate_sentences([search_term])
|
|
|
- logger.info(f"Translation result: {translations}")
|
|
|
+ translation_result = translate_sentences([search_term])
|
|
|
+ logger.info(f"Translation result: {translation_result}")
|
|
|
|
|
|
- if not translations or len(translations) == 0:
|
|
|
+ # Handle translation result
|
|
|
+ if not translation_result or 'translations' not in translation_result:
|
|
|
translated = "翻译失败(无结果)"
|
|
|
- logger.error(f"Translation failed for '{search_term}': No result")
|
|
|
+ logger.error(f"Translation failed for '{search_term}': Invalid result format")
|
|
|
sys.exit(1)
|
|
|
- elif isinstance(translations, int): # Handle case where function returns error code
|
|
|
- translated = f"翻译失败(错误码:{translations})"
|
|
|
- logger.error(f"Translation error for '{search_term}': {translations}")
|
|
|
+
|
|
|
+ translations = translation_result['translations']
|
|
|
+ if not translations or len(translations) == 0:
|
|
|
+ translated = "翻译失败(无结果)"
|
|
|
+ logger.error(f"Translation failed for '{search_term}': No translations in result")
|
|
|
sys.exit(1)
|
|
|
else:
|
|
|
translated = translations[0]
|