File size: 969 Bytes
244baf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

import os
# 设置代理服务器地址和端口
proxy_host = '127.0.0.1'
proxy_port = '7890'
os.environ['http_proxy'] = f'http://{proxy_host}:{proxy_port}'
os.environ['https_proxy'] = f'http://{proxy_host}:{proxy_port}'
import json
import asyncio
from googletrans import Translator

async def main():
    with open("person.json", "r", encoding="utf-8") as f:
        data = json.load(f)

    translator = Translator()

    for term_info in data.get("prompt_terms", []):
        term_text = term_info.get("term", "")
        if term_text:
            try:
                result = await translator.translate(term_text, src="en", dest="ja")
                term_info["japanese"] = result.text
            except Exception as e:
                print(f"翻译失败:{term_text} - {e}")
                term_info["japanese"] = ""

    with open("person_jp.json", "w", encoding="utf-8") as f:
        json.dump(data, f, ensure_ascii=False, indent=2)

asyncio.run(main())