p.py と eng.txt を示します。vscode 上 (on Mac) では import の部分に部分に黄色線が出ますが、問題なく実行できます。
p.py
python3
1from googletrans import Translator # pip install googletrans==4.0.0-rc1
2import os
3
4def main():
5 while True:
6 file_path = input('英語ファイル名?:')
7 if os.path.isfile(file_path):
8 break
9
10 with open(file_path) as f:
11 lines = f.readlines()
12 print(lines)
13
14 translate_lines(lines)
15
16def translate_lines(lines):
17 print("------")
18 tr = Translator()
19 for line in lines:
20 result = tr.translate(line, src='en', dest='ja')
21 print(result.text, ':', result.pronunciation, '<-', line)
22
23if __name__ == "__main__":
24 main()
実行例
