Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V0.9.8.3]无法保留换行符/Unable to keep line breaks #151

Open
infrost opened this issue Nov 2, 2024 · 3 comments
Open

[V0.9.8.3]无法保留换行符/Unable to keep line breaks #151

infrost opened this issue Nov 2, 2024 · 3 comments

Comments

@infrost
Copy link

infrost commented Nov 2, 2024

您好,我是[DeeplxFile](https://github.com/infrost/DeeplxFile) 的开发者,首先非常感谢您的项目,使我的想法成为可能。
在使用您新版本[V0.9.8.3]的程序后,我发现它会导致我现有的项目出现问题,研究后发现该版本API传入请求后(Free EndPoint),似乎无法正确处理换行符,如下例子:

import httpx, json

deeplx_api = "http://127.0.0.1:1188/translate"
data = {
	"text": "Hello World \n Thanks for the developer of DeepLX",
	"source_lang": "EN",
	"target_lang": "ZH"
}
post_data = json.dumps(data)
headers = {"Content-Type": "application/json"} 
r = httpx.post(url = deeplx_api, data = post_data, headers=headers).text
print(r)

程序返回的data中会直接把该换行符替换成空格:

{"alternatives":["你好,世界 感谢 DeepLX 开发人员","你好,世界 感谢 DeepLX 的开发者","你好世界 感谢 DeepLX 开发人员","你好世界 感谢 DeepLX 的开发者"],"code":200,"data":"你好,世界 感谢 DeepLX 开发人员","id":8388902000,"method":"Free","source_lang":"EN","target_lang":"ZH"}

如果我使用\\n这样的转义换行符,则程序返回的是一个左括号,这让我感觉到十分困惑。

{"alternatives":["Hello World (感谢 DeepLX 的开发者","Hello World (感谢 DeepLX 的开发人员","Hello World \\n 感谢 DeepLX 的开发者","Hello World (感谢 DeepLX 开发者"],"code":200,"data":"Hello World (感谢 DeepLX 的开发者","id":8392685000,"method":"Free","source_lang":"EN","target_lang":"ZH"}

此外,如果我尝试传入一个字典,如

dic = ["Hello World","Thanks for the developer of DeepLX"]
data = {
	"text": dic,
	"source_lang": "EN",
	"target_lang": "ZH"
}

程序会直接返回400 Empty data错误。

现在我只能使用一种不那么优雅的方法:把换行符替换成<br>(程序会原封不动地将其传回),然后再把<br>替换回换行符。
此前的版本似乎没有这个问题,我想问这个是一个可以被修复的issue,还是以后的程序逻辑都会是这样了?

image

Hello, I am the developer of DeeplxFile and first of all thank you very much for your project that made my idea possible.
After using your new version [V0.9.3] of the project, I found that it causes problems with my existing project, after investigating it, I found out that this version of the API doesn't seem to be able to handle line breaks correctly after passing in the request (Free EndPoint Method), as shown on the above example: The line break is replaced with a space directly in the data returned by the program. If I use an escape newline like \\n, the program returns a left bracket (, which I find very confusing.
Additionally, if I try to pass it in a dictionary, the programme would simply return a 400 Empty data error.
Now I'm stuck with a less elegant method: replacing line breaks with <br> (which the program passes back as is) and then replacing <br> back with line breaks.
Previous versions don't seem to have this problem, so I'm asking if this is an issue that can be fixed, or if the program logic will be like this from now on?

@missuo
Copy link
Member

missuo commented Nov 2, 2024

Thanks for your feedback, I will fix this issue ASAP.

@infrost infrost changed the title [V0.9.3]无法保留换行符/Unable to keep line breaks [V0.9.8.3]无法保留换行符/Unable to keep line breaks Nov 2, 2024
@alan-zxs
Copy link

alan-zxs commented Nov 13, 2024

Linebreaks \n don't work, hopefully they will fix it in 0.9.8.4

@missuo
Copy link
Member

missuo commented Nov 30, 2024

@infrost

I've tested it and the DeepL API returns the original \n as /n , I'm not sure what to do with that at the moment, it's obviously not a good solution if you use a simple string replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants