|
|
@@ -40,21 +40,17 @@ def insert_empty_column(data, column_index):
|
|
|
def process_row(row, search_term_index):
|
|
|
# Add translation column after search term
|
|
|
search_term = row[search_term_index]
|
|
|
- try:
|
|
|
- print(f"Translating: {search_term}")
|
|
|
- translations = translate_sentences([search_term])
|
|
|
- print(f"Translation result: {translations}")
|
|
|
+ print(f"Translating: {search_term}")
|
|
|
+ translations = translate_sentences([search_term])
|
|
|
+ print(f"Translation result: {translations}")
|
|
|
+
|
|
|
+ if not translations or len(translations) == 0:
|
|
|
+ translated = "翻译失败(无结果)"
|
|
|
+ elif isinstance(translations, int): # Handle case where function returns error code
|
|
|
+ translated = f"翻译失败(错误码:{translations})"
|
|
|
+ else:
|
|
|
+ translated = translations[0]
|
|
|
|
|
|
- if not translations or len(translations) == 0:
|
|
|
- translated = "翻译失败(无结果)"
|
|
|
- elif isinstance(translations, int): # Handle case where function returns error code
|
|
|
- translated = f"翻译失败(错误码:{translations})"
|
|
|
- else:
|
|
|
- translated = translations[0]
|
|
|
-
|
|
|
- except Exception as e:
|
|
|
- print(f"Translation error for '{search_term}': {str(e)}")
|
|
|
- translated = f"翻译失败(异常:{str(e)})"
|
|
|
|
|
|
# Update the row with translation in the new column
|
|
|
row[search_term_index + 1] = translated
|