#!/usr/bin/env python3 # -*- coding: utf-8 -*- import sys import os def fix_corrupted_chars(content): # 损坏字符映射表 char_map = { '杩斿洖': '返回', '用户名璇︽儏': '用户名详情', '娣诲姞瑙掕壊': '添加角色', '鍩烘湰淇℃伅': '基本信息', '瑙掕壊涓庢潈': '角色与权限', '璇ョ敤鎴锋湭鍒嗛厤浠讳綍瑙掕壊': '该用户未分配任何角色', '宸查攢姣': '已启用', '宸查攢鐢': '已禁用', '鐘': '状', '鎴': '态', '鎵': '手', '鏈': '机', '鍚': '号', '鐢': '用', '鎴': '户', '鍚': '名', '閭': '邮', '閾': '箱', '鍒': '创', '寤': '建', '鏃': '时', '闂': '间', '鏈': '最', '鍚': '后', '鏇': '修', '鏀': '改', '鏃': '时', '闂': '间', '浠': '未', '庢': '登', '湭': '录', '璇': '请', '杈': '输', '鍏': '入', '鐢': '用', '鎴': '户', '鍚': '名', '鎴': '密', '鐮': '码', '閭': '邮', '閾': '箱', '鍦': '地', '址': '址', '鎵': '手', '鏈': '机', '鍚': '号', '瑙': '角', '鑹': '色', '鍚': '名', '鎻': '描', '浣': '述', '鍒': '创', '寤': '建', '鏃': '时', '闂': '间', '鏈': '最', '鍚': '后', '鏇': '修', '鏀': '改', '鏃': '时', '闂': '间' } for corrupted, correct in char_map.items(): content = content.replace(corrupted, correct) return content def main(): if len(sys.argv) != 2: print("Usage: python fix_encoding.py ") sys.exit(1) file_path = sys.argv[1] if not os.path.exists(file_path): print(f"File not found: {file_path}") sys.exit(1) try: # Read file with UTF-8 encoding with open(file_path, 'r', encoding='utf-8') as f: content = f.read() # Fix corrupted characters fixed_content = fix_corrupted_chars(content) # Write back the fixed content with open(file_path, 'w', encoding='utf-8') as f: f.write(fixed_content) print(f"Fixed encoding issues in {file_path}") except Exception as e: print(f"Error processing file: {e}") sys.exit(1) if __name__ == "__main__": main()