DeepLcom / deepl-python

Official Python library for the DeepL language translation API.
MIT License
1.06k stars 75 forks source link

Encoding problem when translating to french. #88

Closed One1Tick closed 6 months ago

One1Tick commented 7 months ago

When I translate to french I got issue with accented characters. The py file is encoded under UTF-8.

import deepl auth_key = "myKey" translator = deepl.Translator(auth_key) result = translator.translate_text("The Code GPT extension requires your OpenAI API key", target_lang = "FR") print(result.text)

Result is "L'extension Code GPT n�cessite votre cl� API OpenAI" with � instead of é. What is the issue. Thanks and sorry for the newbie question.

JanEbbing commented 6 months ago

Hi, what (Terminal etc) are you using to display this text? I'd assume the issue is there, the API returns accented characters correctly, but maybe they are not rendered correctly on your screen by the console. To verify this, you could write the translation to a file like this

import deepl
auth_key = "myKey"
translator = deepl.Translator(auth_key)
result = translator.translate_text("The Code GPT extension requires your OpenAI API key", target_lang = "FR")
print(result.text)
with open('output_tmp.txt', 'w') as f:
  f.write(result.text)

and check the produced output_tmp.txt file, it should contain the accented characters. To enable unicode in your console, for Windows there's a SO answer here For Mac OS, Apple has some instructions here Linux should default to UTF-8, which can render this - if it doesn't work on Linux, please check for your distro/terminal or post here with the exact software you are using.

One1Tick commented 6 months ago

Thanks @JanEbbing. The problem was in vscode, it works correctly when launching the script in a windows terminal. Should be a vscode config issue. thanks anyway for your help.