Procházet zdrojové kódy

fix: handle Japanese encoding in CSV processing to prevent garbled text

Your Name (aider) před 1 rokem
rodič
revize
eb99cab7b1
1 změnil soubory, kde provedl 2 přidání a 2 odebrání
  1. 2 2
      translate_new_col.py

+ 2 - 2
translate_new_col.py

@@ -13,7 +13,7 @@ def create_search_link(value):
 
 def read_csv(file_path):
     """读取CSV文件并返回数据列表"""
-    encodings = ['utf-8', 'latin-1', 'gbk']
+    encodings = ['utf-8-sig', 'shift_jis', 'euc-jp', 'utf-16']  # 添加日文常用编码
     for encoding in encodings:
         try:
             with open(file_path, mode='r', encoding=encoding) as file:
@@ -72,7 +72,7 @@ def add_search_links(data, column_index, start_row=0):
 def save_csv(data, file_path):
     """将数据保存为CSV文件"""
     try:
-        with open(file_path, mode='w', newline='', encoding='utf-8') as file:
+        with open(file_path, mode='w', newline='', encoding='utf-8-sig') as file:  # 使用utf-8-sig编码
             writer = csv.writer(file)
             writer.writerows(data)
     except Exception as e: