code is here
import openpyxl
from googletrans import Translator
loc = r"C:\Users\userid\Desktop\translation.xlsx"
gs = Translator.translate()
wb = openpyxl.load_workbook(loc)
sheet = wb.active
for i in range(2, sheet.max_row + 1):
original = sheet.cell(row=i, column=1).value
translated = gs.translate(original, 'de')
sheet.cell(row=i, column=2).value = translated
wb.save(loc)
Error:
Traceback (most recent call last):
File "c:\Users\userid\translation.py", line 8, in <module>
gs = Translator.translate()
TypeError: translate() missing 2 required positional arguments: 'self' and 'text'
You're trying to use the function translate()
with the Translator
class itself, not an instance of it.
Try:
gs = Translator()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.