Comments (14)
Show me Screenshot Pls.
from deeplx.
![截屏2024-04-24 下午2 18 02](https://private-user-images.githubusercontent.com/97672521/325101904-c3f7ae1b-2304-4aef-8d1d-cc216e6391ab.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc1MjY3MDAsIm5iZiI6MTcxNzUyNjQwMCwicGF0aCI6Ii85NzY3MjUyMS8zMjUxMDE5MDQtYzNmN2FlMWItMjMwNC00YWVmLThkMWQtY2MyMTZlNjM5MWFiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MDQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjA0VDE4NDAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNlMDRmNmFlMzBhODI0Nzc0ZDc4OGE2MGJhNWMxMjM4NzM4ZWUwZWJiZjVmOTQyOThiODQ1ZjEwMWZiZTBmZDcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.y6RidNuRkxcdiD_MZopzOYWFCCEqGHRi54LPTdZGaf8)
Show me Screenshot Pls.
the commands are from README.
At first I thought it was my code's issue. So I tested the command with multiple lines. Which didn't work
from deeplx.
In JSON, strings cannot be written directly across lines. You should use newline characters.
curl -X POST http://localhost:1188/translate \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_access_token" \
-d '{
"text": "Hello\nworld!",
"source_lang": "EN",
"target_lang": "DE"
}'
from deeplx.
![image](https://private-user-images.githubusercontent.com/55200481/325103805-11df370b-78cf-4847-a2f3-29cca9ec50fe.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc1MjY3MDAsIm5iZiI6MTcxNzUyNjQwMCwicGF0aCI6Ii81NTIwMDQ4MS8zMjUxMDM4MDUtMTFkZjM3MGItNzhjZi00ODQ3LWEyZjMtMjljY2E5ZWM1MGZlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MDQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjA0VDE4NDAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJjMmZmM2RlOTQ2YzViNTIxOTJiODcxYzNmMmU2YWJhOTM3ZTNjNjM4YjAyMzczNTdjOTI3YjUxNDE0OTljNGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.HMZgt2ALTe31XcI-TeNVLQ5KYgAi9HWH1w_COZhVhcY)
If you use this type of API debugging tool, you'll notice that when you paste something that contains line breaks, it's automatically converted to \n
.
from deeplx.
so what should I do if I want to make it able to do multiple lines. Or is it just not possible?
from deeplx.
so what should I do if I want to make it able to do multiple lines. Or is it just not possible?
Is my expression not clear enough? I have already given you quite clear examples above.
from deeplx.
I hope you have some basic knowledge of coding, at least to the extent that you understand what \n
represents. Otherwise, I think you will not be able to use DeepLX properly.
from deeplx.
understand, i need to convert it to \n then reconvert it back to lines
from deeplx.
understand, i need to convert it to \n then reconvert it back to lines
![image](https://private-user-images.githubusercontent.com/55200481/325105542-4070b92f-d463-469c-a4ec-76f0b6e50762.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTc1MjY3MDAsIm5iZiI6MTcxNzUyNjQwMCwicGF0aCI6Ii81NTIwMDQ4MS8zMjUxMDU1NDItNDA3MGI5MmYtZDQ2My00NjljLWE0ZWMtNzZmMGI2ZTUwNzYyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MDQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjA0VDE4NDAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWU3NmVlOTQ0NTczYThlMmE5YzkxY2Y2MzFkZTMwOGE0NzJkZWIzYTkyYjA0YTU3NzcwNGU5MjgyOTZmNDNmYjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.65-pwAkbX02wue6RC09y9FxxtE3Z-IEsb9t3Gyh0Fcs)
It seems you still haven't understood what I meant. If you extract the data
from the Response, printing it will automatically line break because it contains \n
.
from deeplx.
I need to convert it as well right?(like var=var.replace('\n', '\n')
oh, I'm not printing it. I'm displaying it like a widget so, i convert it back (var=var.replace('\n', '\n'))
from deeplx.
I need to convert it as well right?(like var=var.replace('\n', '\n') oh, I'm not printing it. I'm displaying it like a widget so, i convert it back (var=var.replace('\n', '\n'))
Show me your full code.
from deeplx.
text = data["q"]
target_lang = data["target"]
if "source" in data:
source_lang = data["source"]
deeplx_base_url = os.environ.get("DEEPLX_BASE_URL")
if not deeplx_base_url:
return Response(
status_code=500,
content=json.dumps(
{
"error": {
"message": "No DEEPLX_BASE_URL provided",
}
}
),
)
print(text)
text = text.replace('\n', '\\n')
print(text)
body = {
"text": text,
"target_lang": target_lang,
}
if "source" in data:
body["source_lang"] = source_lang
try:
req = ProxyRequest(
deeplx_base_url, "POST", '', json.dumps(body), query_params={}
# deeplx_base_url, "POST", headers, json.dumps(body), query_params={}
)
resp = await pass_through_request(http_client, req, nohttps=True, noheaders=True)
resp = json.loads(resp.content.decode("utf-8"))
try:
translated_text = resp["alternatives"][0]
print(translated_text)
translated_text = translated_text.replace('\\nn', '\n')
print(translated_text)
res = {"data": {"translations": [{"translatedText": translated_text}]}}
except TypeError:
# res = {"error": {"message": "Failed to translate"}}
# res = {"data": {"translations": [{"translatedText": "Failed to translate"}]}}
res = {"data": {"translations": [{"translatedText": text}]}}
if "source" not in raycast_data:
res["data"]["translations"][0]["detectedSourceLanguage"] = resp[
"source_lang"
].lower()
return Response(status_code=200, content=json.dumps(res))
except Exception as e:
logger.error(f"DEEPLX error: {e}")
return Response(
status_code=500,
content=json.dumps(
{
"error": {
"message": "Unknown error",
}
}
),
)
from deeplx.
replace('\n', '\\n')
Why do this?
from deeplx.
because otherwise it will return {"code":404,"message":"No text to translate}
from deeplx.
Related Issues (20)
- Win10一打开就闪退, 把能关的都关了也无法解决问题, 用ProcessMonitor记录了下崩溃过程 HOT 22
- 沉浸翻译偶尔报错:Unexpected end of JSON input HOT 1
- the response data is blank HOT 1
- v2/translate 接口似乎没有校验 token HOT 1
- v2/translate 接口的 Authorization 头和官方不一致 HOT 7
- Ability to provide auth keys within file HOT 4
- 临时解决时区问题
- 请求添加对树莓派ARM的二进制程序 HOT 5
- can i use my premium session? HOT 3
- 功能建议:术语表
- 批量翻译返回格式和官方不一致 HOT 2
- 是否可用添加ipv6的代理池
- DeeplX doest work? HOT 3
- How to pass below parameters to avoid block? identifier, timestamp HOT 1
- DeepL with immersive-translate Token HOT 2
- [报错] HOT 3
- [error]: 5次重试后依然出错:response.text='',Expecting value: line 1 column 1 (char 0) HOT 1
- 更改端口后原端口并未关闭,而是开启了两个端口,如何将default端口关闭 HOT 3
- 支持 DeepL 官方 API 接口响应格式 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deeplx.