refactor: Internationalize and Clean Up Code Comments

- Translate Chinese comments to English across multiple files
- Improve code readability by using consistent, clear comments
- Remove redundant comments and simplify language-specific annotations
- Maintain existing code structure while enhancing internationalization
This commit is contained in:
yeongpin
2025-03-11 12:09:07 +08:00
parent ff358588bb
commit b98f094407
9 changed files with 145 additions and 145 deletions

View File

@@ -4,10 +4,10 @@ import sys
from colorama import Fore, Style, init
from config import get_config
# 初始化colorama
# Initialize colorama
init()
# 定义emoji和颜色常量
# Define emoji and color constants
EMOJI = {
'DB': '🗄️',
'UPDATE': '🔄',
@@ -23,13 +23,13 @@ class CursorAuth:
def __init__(self, translator=None):
self.translator = translator
# 获取配置
# Get configuration
config = get_config(translator)
if not config:
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('auth.config_error') if self.translator else 'Failed to load configuration'}{Style.RESET_ALL}")
sys.exit(1)
# 根据操作系统获取路径
# Get path based on operating system
try:
if sys.platform == "win32": # Windows
if not config.has_section('WindowsPaths'):
@@ -50,7 +50,7 @@ class CursorAuth:
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('auth.unsupported_platform') if self.translator else 'Unsupported platform'}{Style.RESET_ALL}")
sys.exit(1)
# 验证路径是否存在
# Verify if the path exists
if not os.path.exists(os.path.dirname(self.db_path)):
raise FileNotFoundError(f"Database directory not found: {os.path.dirname(self.db_path)}")
@@ -58,12 +58,12 @@ class CursorAuth:
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('auth.path_error', error=str(e)) if self.translator else f'Error getting database path: {str(e)}'}{Style.RESET_ALL}")
sys.exit(1)
# 检查数据库文件是否存在
# Check if the database file exists
if not os.path.exists(self.db_path):
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('auth.db_not_found', path=self.db_path)}{Style.RESET_ALL}")
return
# 检查文件权限
# Check file permissions
if not os.access(self.db_path, os.R_OK | os.W_OK):
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('auth.db_permission_error')}{Style.RESET_ALL}")
return
@@ -78,12 +78,12 @@ class CursorAuth:
def update_auth(self, email=None, access_token=None, refresh_token=None):
conn = None
try:
# 确保目录存在并设置正确权限
# Ensure the directory exists and set the correct permissions
db_dir = os.path.dirname(self.db_path)
if not os.path.exists(db_dir):
os.makedirs(db_dir, mode=0o755, exist_ok=True)
# 如果数据库文件不存在,创建一个新的
# If the database file does not exist, create a new one
if not os.path.exists(self.db_path):
conn = sqlite3.connect(self.db_path)
cursor = conn.cursor()
@@ -98,17 +98,17 @@ class CursorAuth:
os.chmod(self.db_path, 0o644)
conn.close()
# 重新连接数据库
# Reconnect to the database
conn = sqlite3.connect(self.db_path)
print(f"{EMOJI['INFO']} {Fore.GREEN} {self.translator.get('auth.connected_to_database')}{Style.RESET_ALL}")
cursor = conn.cursor()
# 增加超时和其他优化设置
# Add timeout and other optimization settings
conn.execute("PRAGMA busy_timeout = 5000")
conn.execute("PRAGMA journal_mode = WAL")
conn.execute("PRAGMA synchronous = NORMAL")
# 设置要更新的键值对
# Set the key-value pairs to update
updates = []
updates.append(("cursorAuth/cachedSignUpType", "Auth_0"))
@@ -121,11 +121,11 @@ class CursorAuth:
updates.append(("cursorAuth/refreshToken", refresh_token))
# 使用事务来确保数据完整性
# Use transactions to ensure data integrity
cursor.execute("BEGIN TRANSACTION")
try:
for key, value in updates:
# 检查键是否存在
# Check if the key exists
cursor.execute("SELECT COUNT(*) FROM ItemTable WHERE key = ?", (key,))
if cursor.fetchone()[0] == 0:
cursor.execute("""