0
  1. I want to fix the below code, it should translate the words located in column A in the excel called "translation.xlsx", but it gives me an error
  2. Also it should give me the output/result(translated words) in the same excel(translation.xlsx") in column B.

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'
1
  • It's a TypeError, not translation error. You want gs to be instance of Translator class, so it has to be gs = Translator() Commented Oct 8, 2020 at 17:57

1 Answer 1

1

You're trying to use the function translate() with the Translator class itself, not an instance of it.

Try:

gs = Translator()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.