53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
翻译题目内容
|
||
"""
|
||
import json
|
||
import os
|
||
import re
|
||
|
||
def translate_text(text):
|
||
"""
|
||
翻译文本 - 使用简单的词典替换方式
|
||
这里提供一个框架,实际翻译需要使用翻译API
|
||
"""
|
||
return text
|
||
|
||
def translate_questions(input_file, output_file):
|
||
"""
|
||
翻译所有题目
|
||
"""
|
||
with open(input_file, 'r', encoding='utf-8') as f:
|
||
questions = json.load(f)
|
||
|
||
translated_questions = []
|
||
|
||
for q in questions:
|
||
translated_q = {
|
||
'topic': q['topic'],
|
||
'question_num': q['question_num'],
|
||
'stem_en': q['stem'],
|
||
'stem_cn': translate_text(q['stem']),
|
||
'options': [],
|
||
'answer': q['answer']
|
||
}
|
||
|
||
for opt in q['options']:
|
||
translated_q['options'].append({
|
||
'label': opt['label'],
|
||
'text_en': opt['text'],
|
||
'text_cn': translate_text(opt['text'])
|
||
})
|
||
|
||
translated_questions.append(translated_q)
|
||
|
||
with open(output_file, 'w', encoding='utf-8') as f:
|
||
json.dump(translated_questions, f, ensure_ascii=False, indent=2)
|
||
|
||
print(f"翻译完成,保存到: {output_file}")
|
||
|
||
if __name__ == '__main__':
|
||
input_file = '/Users/duguoyou/D365/exam_data/questions.json'
|
||
output_file = '/Users/duguoyou/D365/exam_data/questions_translated.json'
|
||
translate_questions(input_file, output_file)
|