2025-12-16 23:17:13 +08:00
import os
import re
import json
2025-12-16 23:21:17 +08:00
from pathlib import Path
2025-12-16 23:17:13 +08:00
# Load PATH_TRANSLATION_MAP from JSON
2025-12-17 12:07:37 +08:00
# Ensure the path is relative to the script's location or absolute
script_dir = Path ( __file__ ) . parent
path_translation_map_path = script_dir / 'path_translation_map.json'
with open ( path_translation_map_path , 'r' , encoding = 'utf-8' ) as f :
2025-12-16 23:17:13 +08:00
PATH_TRANSLATION_MAP = json . load ( f )
def translate_path_component ( component ):
if component in PATH_TRANSLATION_MAP :
return PATH_TRANSLATION_MAP [ component ]
# Handle numeric prefixes like (3,1)_#_
if re . match ( r "^\(\d+,\d+\)_#?_" , component ):
cleaned_component = re . sub ( r "^\(\d+,\d+\)_#?_" , "" , component ) . replace ( "_" , " " )
# Try to match cleaned component against known translations
for k , v in PATH_TRANSLATION_MAP . items ():
if cleaned_component in k or k in cleaned_component :
return v . replace ( " " , "_" ) # Return simplified and underscored version
# Fallback for complex patterns not in map
return re . sub ( r "[^a-zA-Z0-9]+" , "_" , cleaned_component ) . strip ( "_" )
# If it's a very long Chinese filename that might have specific terms
2025-12-17 12:07:37 +08:00
# These were added to PATH_TRANSLATION_MAP now, so this generic logic might not be hit as often
if "代码组织" == component : # Exact match for a known common Chinese filename part
return "Code_Organization"
if "编程书籍推荐" == component :
return "Recommended_Programming_Books"
if "通用项目架构模板" == component :
2025-12-16 23:17:13 +08:00
return "General_Project_Architecture_Template"
2025-12-17 12:07:37 +08:00
if "工具集" == component :
2025-12-16 23:17:13 +08:00
return "Tool_Set"
2025-12-17 12:07:37 +08:00
if "系统提示词构建原则" == component :
2025-12-16 23:17:13 +08:00
return "System_Prompt_Construction_Principles"
2025-12-17 12:07:37 +08:00
if "胶水编程" == component :
2025-12-16 23:17:13 +08:00
return "Glue_Programming"
2025-12-17 12:07:37 +08:00
if "vibe-coding-经验收集" == component :
2025-12-16 23:17:13 +08:00
return "vibe-coding-Experience_Collection"
2025-12-17 12:07:37 +08:00
if "开发经验" == component :
2025-12-16 23:17:13 +08:00
return "Development_Experience"
2025-12-17 12:07:37 +08:00
if "学习经验" == component :
2025-12-16 23:17:13 +08:00
return "Learning_Experience"
2025-12-17 12:07:37 +08:00
if "编程之道" == component :
2025-12-16 23:17:13 +08:00
return "The_Way_of_Programming"
2025-12-17 12:07:37 +08:00
if "客观分析" == component :
2025-12-16 23:17:13 +08:00
return "Objective_Analysis"
2025-12-17 12:07:37 +08:00
if "精华技术文档生成提示词" == component :
2025-12-16 23:17:13 +08:00
return "Essential_Technical_Document_Generation_Prompt"
2025-12-17 12:07:37 +08:00
if "智能需求理解与研发导航引擎" == component :
2025-12-16 23:17:13 +08:00
return "Intelligent_Requirement_Understanding_and_R_D_Navigation_Engine"
2025-12-17 12:07:37 +08:00
if "软件工程分析" == component :
2025-12-16 23:17:13 +08:00
return "Software_Engineering_Analysis"
2025-12-17 12:07:37 +08:00
if "系统架构可视化生成Mermaid" :
2025-12-16 23:17:13 +08:00
return "System_Architecture_Visualization_Generation_Mermaid"
2025-12-17 12:07:37 +08:00
if "系统架构" :
2025-12-16 23:17:13 +08:00
return "System_Architecture"
2025-12-17 12:07:37 +08:00
if "简易提示词优化器" :
2025-12-16 23:17:13 +08:00
return "Simple_Prompt_Optimizer"
2025-12-17 12:07:37 +08:00
if "提示工程师任务说明" :
2025-12-16 23:17:13 +08:00
return "Prompt_Engineer_Task_Description"
2025-12-17 12:07:37 +08:00
if "高质量代码开发专家" :
2025-12-16 23:17:13 +08:00
return "High_Quality_Code_Development_Expert"
2025-12-17 12:07:37 +08:00
if "标准项目目录结构" :
2025-12-16 23:17:13 +08:00
return "Standard_Project_Directory_Structure"
2025-12-17 12:07:37 +08:00
if "分析1" :
2025-12-16 23:17:13 +08:00
return "Analysis_1"
2025-12-17 12:07:37 +08:00
if "分析2" :
2025-12-16 23:17:13 +08:00
return "Analysis_2"
2025-12-17 12:07:37 +08:00
if "执行纯净性检测" :
2025-12-16 23:17:13 +08:00
return "Perform_Purity_Test"
2025-12-17 12:07:37 +08:00
if "标准化流程" :
2025-12-16 23:17:13 +08:00
return "Standardized_Process"
2025-12-17 12:07:37 +08:00
if "项目上下文文档生成" :
2025-12-16 23:17:13 +08:00
return "Project_Context_Document_Generation"
2025-12-17 12:07:37 +08:00
if "人机对齐" :
2025-12-16 23:17:13 +08:00
return "Human_AI_Alignment"
2025-12-17 12:07:37 +08:00
if "plan提示词" :
2025-12-16 23:17:13 +08:00
return "Plan_Prompt"
2025-12-17 12:07:37 +08:00
if "Claude Code 八荣八耻" :
2025-12-16 23:17:13 +08:00
return "Claude_Code_Eight_Honors_and_Eight_Shames"
2025-12-17 12:07:37 +08:00
if "任务描述,分析与补全任务" :
2025-12-16 23:17:13 +08:00
return "Task_Description_Analysis_and_Completion"
2025-12-17 12:07:37 +08:00
if "前端设计" :
2025-12-16 23:17:13 +08:00
return "Frontend_Design"
2025-12-17 12:07:37 +08:00
if "输入简单的日常行为的研究报告摘要" :
2025-12-16 23:17:13 +08:00
return "Summary_of_Research_Report_on_Simple_Daily_Behaviors"
2025-12-17 12:07:37 +08:00
if "胶水开发" :
2025-12-16 23:17:13 +08:00
return "Glue_Development"
2025-12-17 12:07:37 +08:00
if "sh控制面板生成" :
2025-12-16 23:17:13 +08:00
return "SH_Control_Panel_Generation"
2025-12-17 12:07:37 +08:00
if "角色定义" :
2025-12-16 23:17:13 +08:00
return "Role_Definition"
2025-12-17 12:07:37 +08:00
if "CLAUDE 记忆" :
2025-12-16 23:17:13 +08:00
return "CLAUDE_Memory"
2025-12-17 12:07:37 +08:00
if "Docs文件夹中文命名提示词" :
2025-12-16 23:17:13 +08:00
return "Docs_Folder_Chinese_Naming_Prompt"
2025-12-17 12:07:37 +08:00
if "通用项目架构综合分析与优化框架" :
2025-12-16 23:17:13 +08:00
return "General_Project_Architecture_Comprehensive_Analysis_and_Optimization_Framework"
2025-12-17 12:07:37 +08:00
if "执行📘_文件头注释规范(用于所有代码文件最上方)" == component :
2025-12-16 23:17:13 +08:00
return "Execute_File_Header_Comment_Specification_for_All_Code_Files"
2025-12-17 12:07:37 +08:00
if "数据管道" == component :
2025-12-16 23:17:13 +08:00
return "Data_Pipeline"
2025-12-17 12:07:37 +08:00
if "项目变量与工具统一维护" == component :
2025-12-16 23:17:13 +08:00
return "Unified_Management_of_Project_Variables_and_Tools"
2025-12-17 12:07:37 +08:00
if "ASCII图生成" == component :
2025-12-16 23:17:13 +08:00
return "ASCII_Art_Generation"
2025-12-17 12:07:37 +08:00
if "Kobe's Diary of Saving Mother, Father, Fiancee, and In-laws × OTE Model Trading Mode × M.I.T White Professor (Accused of Sexual H_arassment by Female Student) v2" == component :
2025-12-16 23:17:13 +08:00
return "Kobe_s_Diary_of_Saving_Mother_Father_Fiancee_and_In_laws_OTE_Model_Trading_Mode_M_I_T_White_Professor_Accused_of_Sexual_Harassment_by_Female_Student_v2" # Simplified for filename
2025-12-17 12:07:37 +08:00
if "动态视图对齐实现文档" == component :
2025-12-16 23:17:13 +08:00
return "Dynamic_View_Alignment_Implementation_Document"
2025-12-17 12:07:37 +08:00
if "Telegram_Bot_按钮和键盘实现模板" == component :
2025-12-16 23:17:13 +08:00
return "Telegram_Bot_Button_and_Keyboard_Implementation_Template"
2025-12-17 12:07:37 +08:00
if "README" == component :
2025-12-16 23:17:13 +08:00
return "README" # Keep README as is
# Default: simply replace spaces with underscores and remove problematic characters for filenames
# For demonstration, a placeholder translation for unseen Chinese
return re . sub ( r "[^a-zA-Z0-9]+" , "_" , component ) . strip ( "_" )
2025-12-16 23:21:17 +08:00
def get_translated_path ( chinese_path_str ): # Accept string
parts = Path ( chinese_path_str ) . parts # Use pathlib to split path
2025-12-16 23:17:13 +08:00
translated_parts = []
# Handle the 'i18n/zh' to 'i18n/en' conversion at the root
if parts [ 0 ] == "i18n" and parts [ 1 ] == "zh" :
translated_parts . append ( "i18n" )
translated_parts . append ( "en" )
remaining_parts = parts [ 2 :]
else :
remaining_parts = parts
for i , part in enumerate ( remaining_parts ):
base , ext = os . path . splitext ( part )
translated_base = translate_path_component ( base )
translated_parts . append ( translated_base + ext )
2025-12-16 23:21:17 +08:00
return Path ( * translated_parts ) # Reconstruct path using pathlib
2025-12-16 23:17:13 +08:00
# Load chinese_files from JSON
2025-12-17 12:07:37 +08:00
chinese_files_list_path = script_dir / 'chinese_files_list.json'
with open ( chinese_files_list_path , 'r' , encoding = 'utf-8' ) as f :
2025-12-16 23:21:17 +08:00
chinese_files_str_list = json . load ( f )
2025-12-17 12:07:37 +08:00
files_to_translate_content = []
2025-12-16 23:17:13 +08:00
2025-12-17 12:07:37 +08:00
for chinese_file_path_str in chinese_files_str_list :
english_file_path = get_translated_path ( chinese_file_path_str ) # Get translated Path object
2025-12-16 23:17:13 +08:00
2025-12-17 12:07:37 +08:00
# Read the content of the English placeholder file
2025-12-16 23:17:13 +08:00
try :
2025-12-17 12:07:37 +08:00
with english_file_path . open ( 'r' , encoding = 'utf-8' ) as f :
content = f . read ()
if content . startswith ( "TRANSLATED CONTENT: \n " ):
chinese_content = content . replace ( "TRANSLATED CONTENT: \n " , "" )
files_to_translate_content . append ({
"chinese_content" : chinese_content ,
"english_target_path" : str ( english_file_path ) # Store as string for easy display
})
2025-12-16 23:21:17 +08:00
except FileNotFoundError :
2025-12-17 12:07:37 +08:00
# This can happen if the previous script run failed for this file
print ( f "Warning: English placeholder file not found for { english_file_path } . Skipping content extraction for this file." )
2025-12-16 23:21:17 +08:00
continue
2025-12-16 23:17:13 +08:00
except Exception as e :
2025-12-17 12:07:37 +08:00
print ( f "Error reading { english_file_path } for content extraction: { e } . Skipping." )
2025-12-16 23:17:13 +08:00
continue
2025-12-17 12:07:37 +08:00
# Output the list of files to translate content for
print ( "--- Files for Content Translation ---" )
for item in files_to_translate_content :
print ( f "Target Path: { item [ 'english_target_path' ] } " )
print ( f "Chinese Content: \n ```markdown \n { item [ 'chinese_content' ] . strip () } \n ``` \n { '=' * 50 } \n " )
print ( f "Total files requiring content translation: { len ( files_to_translate_content ) } " )